Skip to content

Instantly share code, notes, and snippets.

@kkamkou
Created Sep 20, 2012
Embed
What would you like to do?
mod_rewrite caching rules
#author Kanstantsin A Kamkou (2ka.by)
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch SV1; !no_gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain text/html text/xml application/xhtml+xml image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript text/x-js text/ecmascript application/ecmascript text/vbscript text/fluffscript
AddOutputFilterByType DEFLATE image/svg+xml application/x-font-ttf application/x-font font/opentype font/otf font/ttf application/x-font-truetype application/x-font-opentype application/vnd.ms-fontobject application/vnd.oasis.opendocument.formula-template
</IfModule>
<IfModule mod_headers.c>
<FilesMatch \.(css|js)$>
Header append Vary User-Agent
Header append Vary Accept-Encoding
Header append Cache-Control private
</FilesMatch>
<FilesMatch \.(bmp|png|gif|jpe?g|ico|flv|wmv|asf|asx|wma|wax|wmx|wm|swf|pdf|doc|rtf|xls|ppt|eot|ttf|otf|svg)$>
Header append Cache-Control public
</FilesMatch>
<FilesMatch \.(js|css|bmp|png|gif|jpe?g|ico|flv|wmv|asf|asx|wma|wax|wmx|wm|swf|pdf|doc|rtf|xls|ppt)$>
Header unset Last-Modified
FileETag MTime
</FilesMatch>
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
<FilesMatch \.(htm|html|xhtml|xml|shtml|phtml|php)$>
ExpiresDefault "access plus 120 seconds"
</FilesMatch>
ExpiresByType text/html A120
ExpiresByType text/xml A120
ExpiresByType application/xhtml+xml A120
ExpiresByType text/plain A120
<FilesMatch \.css$>
ExpiresDefault "access plus 10 years"
</FilesMatch>
ExpiresByType text/css A315360000
<FilesMatch \.js$>
ExpiresDefault "access plus 10 years"
</FilesMatch>
ExpiresByType text/javascript A315360000
ExpiresByType application/javascript A315360000
ExpiresByType application/x-javascript A315360000
ExpiresByType text/x-js A315360000
ExpiresByType text/ecmascript A315360000
ExpiresByType application/ecmascript A315360000
ExpiresByType text/vbscript A315360000
ExpiresByType text/fluffscript A315360000
<FilesMatch \.(bmp|png|gif|jpe?g|ico)$>
ExpiresDefault "access plus 10 years"
</FilesMatch>
ExpiresByType image/gif A315360000
ExpiresByType image/png A315360000
ExpiresByType image/jpeg A315360000
ExpiresByType image/x-icon A315360000
ExpiresByType image/bmp A315360000
<FilesMatch \.(eot|ttf|otf|svg)$>
ExpiresDefault "access plus 10 years"
</FilesMatch>
ExpiresByType application/x-font-opentype A315360000
ExpiresByType application/x-font-truetype A315360000
ExpiresByType application/x-font-ttf A315360000
ExpiresByType application/x-font A315360000
ExpiresByType font/opentype A315360000
ExpiresByType font/otf A315360000
ExpiresByType application/vnd.oasis.opendocument.formula-template A315360000
ExpiresByType image/svg+xml A315360000
ExpiresByType application/vnd.ms-fontobject A315360000
ExpiresByType font/woff A315360000
<FilesMatch \.(flv|wmv|asf|asx|wma|wax|wmx|wm|mp4|mov)$>
ExpiresDefault "access plus 10 years"
</FilesMatch>
ExpiresByType video/x-flv A315360000
ExpiresByType video/x-ms-wmv A315360000
ExpiresByType video/x-ms-asf A315360000
ExpiresByType video/x-ms-asx A315360000
ExpiresByType video/x-ms-wma A315360000
ExpiresByType video/x-ms-wax A315360000
ExpiresByType video/x-ms-wmx A315360000
ExpiresByType video/x-ms-wm A315360000
<FilesMatch \.(swf|pdf|doc|rtf|xls|ppt)$>
ExpiresDefault "access plus 10 years"
</FilesMatch>
ExpiresByType application/x-shockwave-flash A315360000
ExpiresByType application/pdf A315360000
ExpiresByType application/msword A315360000
ExpiresByType application/rtf A315360000
ExpiresByType application/vnd.ms-excel A315360000
ExpiresByType application/vnd.ms-powerpoint A315360000
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment