Created
April 15, 2015 18:49
-
-
Save SeriouslyAwesome/f690e95e067d97d1e282 to your computer and use it in GitHub Desktop.
Google PageSpeed / Yahoo! YSlow Apache Config for Static Sites
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
# Protect files and directories | |
<FilesMatch "(\.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)? |xtmpl)|code-style\.pl|Entries.*|Repository|Root|Tag|Template)$"> | |
Order allow,deny | |
</FilesMatch> | |
# Don’t show directory listings | |
Options -Indexes | |
# Basic rewrite rules, stop unneeded PERL bot, block subversion directories | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteRule ^(.*/)?\.svn/ - [F,L] | |
ErrorDocument 403 "Access Forbidden" | |
RewriteCond %{HTTP_USER_AGENT} libwww-perl.* | |
RewriteRule .* – [F,L] | |
DirectorySlash On | |
</IfModule> | |
<IfModule mod_headers.c> | |
# Turn on Expires and set default expires to 3 days | |
ExpiresActive On | |
ExpiresDefault A259200 | |
FileETag none | |
# Set up caching on media files for 1 month | |
<FilesMatch ".(ico|gif|jpg|jpeg|png|flv|pdf|swf|mov|mp3|wmv|ppt|xml|txt|html|js|css|eot|svg|ttf|woff|woff2)$"> | |
ExpiresDefault A2419200 | |
# Header append Cache-Control "public" | |
</FilesMatch> | |
# Force no caching for dynamic files | |
<FilesMatch ".(php|cgi|pl|htm)$"> | |
ExpiresDefault A0 | |
Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0" | |
Header set Pragma "no-cache" | |
</FilesMatch> | |
</IfModule> | |
# ---------------------------------------------------------------------- | |
# Gzip compression | |
# ---------------------------------------------------------------------- | |
<IfModule mod_deflate.c> | |
# Force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/ | |
<IfModule mod_setenvif.c> | |
<IfModule mod_headers.c> | |
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding | |
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding | |
</IfModule> | |
</IfModule> | |
# Compress all output labeled with one of the following MIME-types | |
AddOutputFilterByType DEFLATE application/atom+xml \ | |
application/javascript \ | |
application/json \ | |
application/rss+xml \ | |
application/vnd.ms-fontobject \ | |
application/x-font-ttf \ | |
application/xhtml+xml \ | |
application/xml \ | |
font/opentype \ | |
image/svg+xml \ | |
image/x-icon \ | |
text/css \ | |
text/html \ | |
text/plain \ | |
text/x-component \ | |
text/xml | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment