Created
January 13, 2013 07:33
-
-
Save jcanfield/4522839 to your computer and use it in GitHub Desktop.
htaccess Configuration for Wordpress (Developed for a client project and utilizes Caching, Correct Timezones, ETAG Configuration, Compression and Basic Rewrites.
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
# .htaccess for some-website.com | |
# By Joshua Canfield (Code Clarity) | |
# Features include Page Caching by FilesMatch, mod_expires & mod_header. Also uses old website 301 Redirections | |
# Sets Timezone to Mountain | |
SetEnv TZ America/Denver | |
# Turn on Expires and set default to 0 | |
ExpiresActive On | |
ExpiresDefault A0 | |
# Set up caching on media files for 1 year (forever?) | |
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$"> | |
ExpiresDefault A29030400 | |
Header append Cache-Control "public" | |
</FilesMatch> | |
# Set up caching on media files for 1 week | |
<FilesMatch "\.(gif|jpg|jpeg|png|swf)$"> | |
ExpiresDefault A604800 | |
Header append Cache-Control "public" | |
</FilesMatch> | |
# Set up 2 Hour caching on commonly updated files | |
<FilesMatch "\.(xml|txt|html|js|css)$"> | |
ExpiresDefault A7200 | |
Header append Cache-Control "proxy-revalidate" | |
</FilesMatch> | |
# Force no caching for dynamic files | |
<FilesMatch "\.(php|cgi|pl|htm)$"> | |
ExpiresActive Off | |
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform" | |
Header set Pragma "no-cache" | |
</FilesMatch> | |
<IfModule mod_deflate.c> | |
# place filter 'DEFLATE' on all outgoing content | |
SetOutputFilter DEFLATE | |
# exclude uncompressible content via file type | |
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|rar|zip)$ no-gzip | |
<IfModule mod_headers.c> | |
# properly handle requests coming from behind proxies | |
Header append Vary User-Agent | |
</IfModule> | |
</IfModule> | |
# BEGIN supercache | |
<IfModule mod_mime.c> | |
<FilesMatch "\.html\.gz$"> | |
ForceType text/html | |
FileETag None | |
</FilesMatch> | |
AddEncoding gzip .gz | |
AddType text/html .gz | |
</IfModule> | |
<IfModule mod_deflate.c> | |
SetEnvIfNoCase Request_URI \.gz$ no-gzip | |
</IfModule> | |
<IfModule mod_headers.c> | |
Header set Vary "Accept-Encoding, Cookie" | |
Header set Cache-Control 'max-age=3, must-revalidate' | |
</IfModule> | |
<IfModule mod_expires.c> | |
ExpiresActive On | |
ExpiresByType text/html A3 | |
</IfModule> | |
# END supercache | |
# BEGIN W3TC Page Cache core | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteBase / | |
RewriteRule ^(.*\/)?w3tc_rewrite_test$ $1?w3tc_rewrite_test=1 [L] | |
RewriteCond %{HTTP:Accept-Encoding} gzip | |
RewriteRule .* - [E=W3TC_ENC:_gzip] | |
RewriteCond %{REQUEST_METHOD} !=POST | |
RewriteCond %{QUERY_STRING} ="" | |
RewriteCond %{HTTP_HOST} =www.some-website.com | |
RewriteCond %{REQUEST_URI} \/$ [OR] | |
RewriteCond %{REQUEST_URI} (sitemap(_index)?\.xml(\.gz)?|[a-z0-9_\-]+-sitemap([0-9]+)?\.xml(\.gz)?) [NC] | |
RewriteCond %{REQUEST_URI} !(\/wp-admin\/|\/xmlrpc.php|\/wp-(app|cron|login|register|mail)\.php|\/feed\/|wp-.*\.php|index\.php) [NC,OR] | |
RewriteCond %{REQUEST_URI} (wp-comments-popup\.php|wp-links-opml\.php|wp-locations\.php) [NC] | |
RewriteCond %{HTTP_COOKIE} !(comment_author|wp-postpass|wordpress_\[a-f0-9\]\+|wordpress_logged_in) [NC] | |
RewriteCond %{HTTP_USER_AGENT} !(W3\ Total\ Cache/0\.9\.2\.4) [NC] | |
RewriteCond "%{DOCUMENT_ROOT}/wp-content/w3tc/pgcache/%{REQUEST_URI}/_index%{ENV:W3TC_UA}%{ENV:W3TC_REF}%{ENV:W3TC_SSL}.html%{ENV:W3TC_ENC}" -f | |
RewriteRule .* "/wp-content/w3tc/pgcache/%{REQUEST_URI}/_index%{ENV:W3TC_UA}%{ENV:W3TC_REF}%{ENV:W3TC_SSL}.html%{ENV:W3TC_ENC}" [L] | |
</IfModule> | |
# END W3TC Page Cache core | |
# BEGIN W3TC Page Cache cache | |
FileETag None | |
AddDefaultCharset UTF-8 | |
<IfModule mod_mime.c> | |
AddType text/html .html_gzip | |
AddEncoding gzip .html_gzip | |
AddType text/xml .xml_gzip | |
AddEncoding gzip .xml_gzip | |
</IfModule> | |
<IfModule mod_deflate.c> | |
SetEnvIfNoCase Request_URI \.html_gzip$ no-gzip | |
SetEnvIfNoCase Request_URI \.xml_gzip$ no-gzip | |
</IfModule> | |
<IfModule mod_headers.c> | |
Header set X-Pingback "http://www.some-website.com/xmlrpc.php" | |
Header set Vary "Accept-Encoding, Cookie" | |
</IfModule> | |
# END W3TC Page Cache cache | |
RedirectMatch 301 /login$ http://www.some-website.com/wp-admin | |
# BEGIN WordPress | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteBase / | |
RewriteRule ^category/(.+)$ http://www.some-website.com/articles/$1 [R=301,L] | |
RewriteRule ^index\.php$ - [L] | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule . /index.php [L] | |
</IfModule> | |
# END WordPress |
The .htaccess
could be improved by utilizing AddType
for MIME support and additional Compression using the following:
AddType application/javascript js
AddType audio/ogg oga ogg
AddType audio/mp4 m4a
AddType video/ogg ogv
AddType video/mp4 mp4 m4v
AddType video/webm webm
AddType image/svg+xml svg svgz
AddEncoding gzip svgz
AddType application/vnd.ms-fontobject eot
AddType application/x-font-ttf ttf ttc
AddType font/opentype otf
AddType application/x-font-woff woff
AddType image/x-icon ico
AddType image/webp webp
AddType text/cache-manifest appcache manifest
AddType text/x-component htc
AddType application/x-chrome-extension crx
AddType application/x-xpinstall xpi
AddType application/octet-stream safariextz
AddType text/x-vcard vcf
<IfModule mod_deflate.c>
<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>
<IfModule filter_module>
FilterDeclare COMPRESS
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/json
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xhtml+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/rss+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/atom+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/vnd.ms-fontobject
FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml
FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-font-ttf
FilterProvider COMPRESS DEFLATE resp=Content-Type $font/opentype
FilterChain COMPRESS
FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no
</IfModule>
<IfModule !mod_filter.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
</IfModule>
</IfModule>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using WP Super Cache I would add the following: