Created
June 11, 2012 13:34
-
-
Save millermedeiros/2910118 to your computer and use it in GitHub Desktop.
basic htaccess for perf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DirectoryIndex index.html index.htm index.php | |
ErrorDocument 404 /404 | |
# Block directory listing | |
Options -Indexes | |
# === URL Rewrite === # | |
# Map all URIs except those corresponding to existing files/folders to the handler | |
RewriteEngine on | |
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d | |
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f | |
RewriteRule ^([\w-_\/]+)?$ ./index.php?p=$1 | |
# === Performance === # | |
# Turn on expires | |
ExpiresActive On | |
# Set up gzip and strong caching and remove eTags | |
<Files ~ "\.(js|css)$"> | |
SetOutputFilter DEFLATE | |
FileETag None | |
ExpiresDefault "access plus 1 year" | |
Header append Cache-Control "private, must-revalidate" | |
</Files> | |
# Set up strong caching and configure eTags | |
<Files ~ "\.(ico|gif|jpe?g|png)$"> | |
FileETag MTime Size | |
ExpiresDefault "access plus 1 year" | |
Header append Cache-Control "public" | |
</Files> | |
# Force gzip and no-caching for dynamic files | |
<FilesMatch "\.(php|cgi|pl|htm?l|xml|rss|json)$"> | |
SetOutputFilter DEFLATE | |
ExpiresDefault A0 | |
Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0" | |
Header set Pragma "no-cache" | |
</FilesMatch> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@netojoaobatista Yes, it all depends on the kind of application you are building. For most of my projects the settings above are the expected output but sometimes JSON/XML files should also be cached forever. It is not a one size fits all solution, it should be adapted based on the needs of the project.