Apache 使用htaccess进行缓存控制EXPIRES BY TYPE

# Cache Control with .htaccess EXPIRES BY TYPE
# from http://forum.powweb.com/showthread.php?t=62786

### turn on the Expires engine
ExpiresActive On

### expires after a month in the client's cache
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType application/pdf A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType text/plain A2592000

### expires after 4.8 hours
ExpiresByType text/css A17200

# Please note that the "A" before the numbers above stands for Access.
# This means that the stopwatch starts when a client accesses the file.
# You can also use "M" for modified.

# TIME CHEAT SHEET
#      300   5 MIN
#      600  10 MIN
#      900  15 MIN
#     1800  30 MIN
#     2700  45 MIN
#
#     3600   1 HR
#     7200   2 HR
#    10800   3 HR
#    14400   4 HR
#    18000   5 HR
#    36000  10 HR
#    39600  11 HR
#    43200  12 HR
#    46800  13 HR
#    50400  14 HR
#    54000  15 HR
#    86400  24 HR
#
#    86400   1 DAY
#   172800   2 DAY
#   259200   3 DAY
#   345600   4 DAY
#   432000   5 DAY
#   518400   6 DAY
#   604800   7 DAY
#
#   604800   1 WEEK
#  1209600   2 WEEK
#  1814400   3 WEEK
#  2419200   4 WEEK
#
#  2419200   1 MONTH (FEBRUARY)
#  2505600   1 MONTH (FEBRUARY LEAP YEAR)
#  2592000   1 MONTH (APRIL, JUNE, SEPTEMBER, NOVEMBER)
#  2678400   1 MONTH (JANUARY, MARCH, MAY, JULY, AUGUST, OCTOBER, DECEMBER)
# 31536000  12 MONTH

Apache 将HTML文件解析为PHP

AddType application/x-httpd-php .html

Apache CodeIgniter Starter .htaccess

### Turn on Rewrite Engine to remove index.php from URL
<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
	
	# Force www. in the domain name.
	# RewriteCond %{HTTP_HOST} !^www.dreyervitals.com$
	# RewriteRule ^(.*)$ http://www.dreyervitals.com/$1 [R=301]

</IfModule>

Apache 在网址中强制WWW

# force www in url
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
# END force www in url

Apache 从域别名转发到主域

# forward from domain aliases
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?domain3\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?and_so_on\.com [NC]
RewriteRule (.*) http://maindomain.com/$1 [R=301,L]
# END forward from domain aliases

Apache 压缩html,css,xml,js

# Compress output
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

Apache Mod Rewrite

#Redirecting to lowercase

	RewriteMap  lc int:tolower
	RewriteCond %{REQUEST_URI} [A-Z]
	RewriteRule (.*) ${lc:$1} [R=301,L]


#This rule is perfect to redirecting the hundreds of daily requests for misplaced robots.txt files such as the following:
#  http://dominio.com/foo/robots.txt
#  http://dominio.com/foo/bar/robots.txt
#  http://dominio.com/foo/2009/05/09/robots.txt
#  http://dominio.com/foo/bar/xyz/robots.txt

	RedirectMatch 301 robots\.txt http://dominio.com/robots.txt


#Redirect favicon.ico & favicon.gif

	RedirectMatch 301 favicon\.ico http://perishablepress.com/favicon.ico
	RedirectMatch 301 favicon\.gif http://perishablepress.com/favicon.ico


#Error 404

	ErrorDocument 404 errors/404.html


#Environment Variables

	SetEnv APPLICATION_ENV development

#Cache

	#1 Year
	<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
		Header set Cache-Control "public"
		Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
		Header unset Last-Modified
	</FilesMatch>

	#2 Hours
	<FilesMatch "\.(html|htm|xml|txt|xsl)$">
		Header set Cache-Control "max-age=7200, must-revalidate"
	</FilesMatch>

	<FilesMatch "\.(js|css)$">
		SetOutputFilter DEFLATE
		Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
	</FilesMatch>


#Compress output using GZIP

	<IfModule mod_gzip.c>  
		mod_gzip_on       Yes  
		mod_gzip_dechunk  Yes  
		mod_gzip_item_include file      \.(html?|txt|css|js|php|pl)$  
		mod_gzip_item_include handler   ^cgi-script$  
		mod_gzip_item_include mime      ^text/.*  
		mod_gzip_item_include mime      ^application/x-javascript.*  
		mod_gzip_item_exclude mime      ^image/.*  
		mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*  
	</IfModule>


#Redirecting non www URL to www URL

	RewriteEngine On  
	RewriteCond %{HTTP_HOST} ^viralpatel\.net$  
	RewriteRule (.*) http://www.viralpatel.net/$1 [R=301,L]


#Change Charset and Language headers

	AddDefaultCharset UTF-8
	DefaultLanguage ens-ES


#Send Custom Headers

	Header set X-Pingback "http://www.askapache.com/xmlrpc.php"  
	Header set Content-Language "es-ES"

Apache Codeigniter .htaccess

RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]