Apache Mercurial的Apache配置

# Password zone
        <Location /hg/ecla>
                AuthType Basic
                Order allow,deny
                Allow from all
                AuthName "Mercurial private area"
                Require valid-user
                AuthUserFile  /var/hg/passfile.pass
        </Location>


        RewriteEngine on
        RewriteRule ^/hg(.*) /var/hg/hgwebdir.cgi$1

        <Directory "/var/hg/">
                Options ExecCGI
                AddHandler cgi-script .cgi
        </Directory>

Apache 在Apache上运行Wordpress的相当永久链接

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /designblog/
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule . /designblog/index.php [L]
</IfModule>

Apache 保护您的wp-includes文件夹

Order Allow,Deny
Deny from all
<Files ~ ".(css|jpe?g|png|gif|js|swf)$">
Allow from all

Apache 网址重定向

RewriteEngine On
rewritecond %{http_host} ^yoursite.com
rewriteRule ^(.*) http://www.yoursite.com/$1 [R=301,L]

Apache Apache命令

mate /etc/apache2/httpd.conf
mate /etc/hosts
mate /private/etc/apache2/extra/httpd-vhosts.conf
sudo apachectl restart
sudo apachectl graceful
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist
sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist

Apache 使用带有Expires By Type的mod_expires的Apache Cache Control

<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresDefault "now"
    ExpiresByType text/html "now"
    ExpiresByType text/xml "now"
    ExpiresByType text/css "access plus 8 hours"
    ExpiresByType text/plain "access plus 8 hours"
    ExpiresByType application/x-javascript "access plus 8 hours"
    ExpiresByType application/x-shockwave-flash "access plus 8 hours"
    ExpiresByType application/pdf "access plus 8 hours"
    ExpiresByType image/gif "access plus 8 hours"
    ExpiresByType image/png "access plus 8 hours"
    ExpiresByType image/jpeg "access plus 8 hours"
    ExpiresByType image/x-icon "access plus 8 hours"
    ExpiresByType video/x-flv "access plus 8 hours"
    ExpiresByType video/quicktime "access plus 8 hours"
</IfModule>

Apache 阻止访问多种文件类型

<FilesMatch "\.(htaccess|htpasswd|php|html|asp|aspx|htm|cgi|pl|php4)$">
Order Allow,Deny
Deny from all
</FilesMatch>

Apache Apache重写规则

<IfModule rewrite_module>
Options +FollowSymLinks
RewriteEngine ON
RewriteLog /Developer/Servers/apache2/logs/mod_rewrite.log
RewriteLogLevel 2

# BlogCFC URL Rewrite Rules
#RewriteRule ^/([A-Za-z0-9-]+)/projects/blog/([\w]+)/index.cfm/(.*)$ /$1/projects/blog/$2/index.cfm?blogParams=$3 [PT,L]
# Blog URL Rewrite Rules
RewriteRule ^/([A-Za-z0-9-]+)/projects/blog/([\w]+)/index.cfm/(.*)$ /$1/projects/blog/$2/index.cfm?blog_param=$3 [R]

RewriteCond %{QUERY_STRING} ^blog_alias=([\w]+)(.*)$ [NC]
RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/index\.cfm /$1/projects/$2/%1/?%2 [R]
# If trailing slash is not provided...add trailing slash, and go to default site
RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)$ /$1/projects/$2/default/ [R]
# If site is not provided...go to default site
RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/$ /$1/projects/$2/default/ [R]
# If site is provided, but trailing slash is not provided...add trailing slash, and go to site
RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/([\w]+)$ /$1/projects/$2/$3/ [R]
# If loading an include...pass on through
RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/([\w]+)/includes/(.*)$ /$1/projects/$2/includes/$4 [QSA,PT,L]
RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/([\w]+)/admin/(.*)$ /$1/projects/$2/admin/$4?blog_alias=$3 [QSA,PT,L]
# site is provided, and all is good...pass on through
#RewriteRule ^/([A-Za-z0-9-]+)/(blog[0-9]*)/([\w]+)/(.*)$ /$1/$2/index.cfm?blog_alias=$3 [QSA,PT,L]
RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/([\w]+)/(.*)$ /$1/projects/$2/$4?blog_alias=$3 [QSA,PT,L]

# CMS URL Rewrite Rules
RewriteCond %{QUERY_STRING} ^site_alias=([\w]+)(.*)$ [NC]
RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)/index\.cfm /$1/projects/$2/%1/?%2 [R]
# If trailing slash is not provided...add trailing slash, and go to default site
RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)$ /$1/projects/$2/default/ [R]
# If site is not provided...go to default site
RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)/$ /$1/projects/$2/default/ [R]
# If site is provided, but trailing slash is not provided...add trailing slash, and go to site
RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)/([\w]+)$ /$1/projects/$2/$3/ [R]
# If loading an asset...pass on through
RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)/([\w]+)/assets/(.*)$ /$1/projects/$2/assets/$4 [QSA,PT,L]
# site is provided, and all is good...pass on through
RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)/([\w]+)/(.*)$ /$1/projects/$2/index.cfm?site_alias=$3 [QSA,PT,L]
</IfModule>

Apache 使用mod_rewrite强制HTTPS

RewriteEngine on
RewriteCond %{HTTPS} !On
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301]

Apache apache配置文件从url中删除www

RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com$1 [R=301,L]