Apache apache中的gzip文件

# Gzip all text-based files
<FilesMatch "\.(php|html|css|js)$">
SetOutputFilter DEFLATE
</FilesMatch>

Apache Apache中的简单Hotlinking

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?google\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?bloglines\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{REQUEST_FILENAME} !hotlink.png$
RewriteRule .*\.(jpe?g|gif|bmp|png)$ http://mysite.com/img/hotlink.png [L]

Apache 重定向到主域

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^sitening.com
RewriteRule (.*) http://sitening.com/$1 [R=301,L]

Apache Drupal .htaccess用于启用干净的URL

# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on

# If your site can be accessed both with and without the 'www.' prefix, you
# can use one of the following settings to redirect users to your preferred
# URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
#
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# adapt and uncomment the following:
# RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
# RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
#
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment and adapt the following:
# RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
# RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

# Modify the RewriteBase if you are using Drupal in a subdirectory or in a
# VirtualDocumentRoot and the rewrite rules are not working properly.
# For example if your site is at http://example.com/drupal uncomment and
# modify the following line:
# RewriteBase /drupal
#
# If your site is running in a VirtualDocumentRoot at http://example.com/,
# uncomment the following line:
# RewriteBase /

# Rewrite URLs of the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>

Apache .htaccess从mod_rewrite中排除目录

RewriteCond %{REQUEST_URI} !^/name-of-directory(/.*)?$ [NC]
RewriteRule .* rewrite?%{REQUEST_URI} [L]

Apache 将404错误页面重定向到任何页面

ErrorDocument 404  http://www.your_site_name.tld

Apache 保护目录

Options -Indexes
DirectoryIndex index.html index.php /index.php

Apache 在cron上重启apache

Create a file in /etc/cron.hourly/

chmod it to 755

make it contain:

#!/bin/bash

if [ -z "$(pidof httpd)" ]; then service httpd restart; fi

Apache 强制所有相关文件类型的gzip压缩。

# Compress all text, html, css, and javascript:
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript

# Or, compress certain file types by extension:
<Files *.html>
SetOutputFilter DEFLATE
</Files>

Apache Apache重定向从* .example.com到example.com

#****************************************
# Apache redirect from *.example.com to example.com
#****************************************

RewriteEngine on

#the domain does not match "example.com"  
#note that you need the end-of-string character $ or it wouldn't catch something like "example.com.example.com"  
RewriteCond %{HTTP_HOST} !^example\.com$

#replace the remainder of the URL: (.*)  
#with the full URL: http://example.com/$1  
#make it a permanent redirect: R=301  
#stop rewriting and do the redirection immediately: L  
RewriteRule (.*) http://example.com/$1 [R=301,L]