Apache 指向网站中的错误页面时避免无限循环

## Avoids infinite loops when pointing
## to error pages in the website
RewriteCond %{REQUEST_URI} ^/(stats/|missing\.html|failed_auth\.html|error/).* [NC]
RewriteRule .* - [L]

Apache HTACCESS - 将旧页面重定向到新页面

Redirect 301 /oldpage.html http://www.domain.com/newpage.html

Apache 保护Apache conf中的svn和CVS路径/目录

<DirectoryMatch "^/.*/(\.svn|CVS)/">
        Order deny,allow
        Deny from all 
</DirectoryMatch>

Apache 生成Apache Development Server SSL密钥

:: Generates a new server key file for a development server

ECHO OFF

TITLE Creating a Development Server Key

ECHO Creating a Development Server Key...

:: Generate server.key
openssl genrsa -des3 -out server.key 1024

:: Generate server.csr and server.pem
openssl req -config ../conf/openssl.cnf -new -out server.csr -keyout server.pem

:: Regenerate server.key from created server.pem
openssl rsa -in server.pem -out server.key

:: Signs the key file and outputs server.cert
openssl x509 -in server.csr -out server.cert -req -signkey server.key -days 365

:: Copy generated files to 'ssl' folder
ECHO Copying generated files to 'SSL' folder
copy "server.key" "../ssl/server.key"
copy "server.cert" "../ssl/server.cert"
copy "server.csr" "../ssl/server.csr"
copy "server.pem" "../ssl/server.pem"

ECHO Development Server Key Created and Copied to SSL folder

pause

Apache 阻止来自用户代理的所有请求

#Block bad bots
SetEnvIfNoCase user-Agent ^FrontPage [NC,OR]
SetEnvIfNoCase user-Agent ^Java.* [NC,OR]
SetEnvIfNoCase user-Agent ^Microsoft.URL [NC,OR]
SetEnvIfNoCase user-Agent ^MSFrontPage [NC,OR]
SetEnvIfNoCase user-Agent ^Offline.Explorer [NC,OR]
SetEnvIfNoCase user-Agent ^[Ww]eb[Bb]andit [NC,OR]
SetEnvIfNoCase user-Agent ^Zeus [NC]
<limit get="" post="" head="">
Order Allow,Deny
Allow from all
Deny from env=bad_bot
</limit>

Apache 用于Apache 2.0的mod_deflate

AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript application/json  
Header append Vary Accept-Encoding

Apache 服务器上的所有FTP用户

mysql psa -e "SELECT REPLACE(sys_users.home,'/home/httpd/vhosts/','') AS domain,sys_users.login,accounts.password FROM sys_users LEFT JOIN accounts on sys_users.account_id=accounts.id ORDER BY sys_users.home ASC;"

Apache 缓存映像Apache Server

# 1 YEAR
<FilesMatch "\.(ico|pdf|flv)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>

# 1 WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>

# 2 DAYS
<FilesMatch "\.(xml|txt|css|js)$">
Header set Cache-Control "max-age=172800, proxy-revalidate"
</FilesMatch>

Apache .htaccess将www子域重定向到二级域

# Redirect without www prefix
RewriteCond %{HTTP_HOST} ^www\.example\.net$ [NC]
RewriteRule ^(.*)$ http://example.net/$1 [r=301,NC,L]

Apache 默认HTAccess

<FilesMatch ".(ini)$">
Order allow,deny
deny from all
</FilesMatch>

Options +FollowSymlinks
Options All -Indexes
RewriteEngine on


#########################################
# rewrite all non www urls to www urls
#########################################
RewriteCond %{HTTP_HOST} !^www.sitename.com$
RewriteRule ^(.*)$ http://www.sitename.com/$1 [R=301,L]


#########################################
# add trailing slashes to directories
#########################################
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !example.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://sitename.com/$1/ [L,R=301]


#########################################
# 404 page
#########################################
ErrorDocument 404 /404.php


#########################################
# 301 Redirects
#########################################
redirect 301 /old/old.htm http://www.sitename.com/new/new.htm


#########################################
# secure pages
#########################################
#RewriteCond %{REQUEST_URI} /cart.php [OR]
#RewriteCond %{SERVER_PORT} 80 
#RewriteRule ^(.*)$ https://www.sitename.com/$1 [R,L]


#########################################
# unsecure pages
#########################################
#RewriteCond %{REQUEST_URI} /products [OR]
#RewriteCond %{SERVER_PORT} 443 
#RewriteRule ^(.*)$ http://www.sitename.com/$1 [R,L]