Best collection of code for your .htaccess file [closed]

We have the Best Collection of Code for your functions.php file thread, so I thought that it might be useful to create a thread for our .htaccess files.

AND PLEASE REMEMBER TO ADD ANY OF YOUR OWN SNIPPETS TO THIS LIST

7

These are 3 snippet for better performance, regarding Yahoo! rules:

Disable Etags:

Header unset ETag
FileETag None

Add expire headers:

<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Tue, 16 Jun 2020 20:00:00 GMT"
</FilesMatch>

Or

ExpiresActive On
ExpiresByType text/html "access plus 1 day"
ExpiresByType image/gif "access plus 10 years"
ExpiresByType image/jpeg "access plus 10 years"
ExpiresByType image/png "access plus 10 years"
ExpiresByType text/css "access plus 10 years"
ExpiresByType text/javascript "access plus 10 years"
ExpiresByType application/x-javascript "access plus 10 years"

Compress plain text file:

<FilesMatch "\.(js|css|html|htm|php|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>

Read more about them here.

Updated:

Redirect requests to www domain

RewriteCond %{HTTP_HOST} !^www\.domain\.tld [NC]
RewriteRule ^(.*)$ http://www.domain.tld/$1 [R=301,L]

Block request to xmlrpc.php

Use this only when you don’t use remote publishing as it can prevent your blog from hacks.

RewriteRule ^(.*)xmlrpc\.php$ http://www.domain.tld [R=301,L]

Redirect all feeds to feedburner

RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC]
RewriteRule ^feed/?.*$ http://feeds.feedburner.com/feed_uri [R=301,NC,L]

Leave a Comment