Friday, March 22, 2013

.htaccess cheat sheet

cheat sheet of .htaccess

1.Unify and Use a 301 redirect from to to tell SEs that the 2domains are the same thing so there's no PageRank leakage.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^kavoir\.com [NC]
RewriteRule ^(.*)$$1 [R=301]

2.Block spammers!
# This blocks and * from accessing your site.
<limit GET POST PUT>
order deny,allow
deny from
deny from
allow from all

3.Change default page!
# The order is followed as specified:
DirectoryIndex default.htm default.php index.html index.php

4.Enable directory browsing!
Options +Indexes
# block a few types of files from showing:
IndexIgnore *.wmv *.mp4 *.avi
Disable directory browsing!
Options All -Indexes

5.Customize error messages!
ErrorDocument 403 /forbidden.html
ErrorDocument 404 /notfound.html
ErrorDocument 500 /servererror.html
6.Get SSI working with HTML/SHTML!

AddType text/html .html
AddType text/html .shtml
AddHandler server-parsed .html
AddHandler server-parsed .shtml

7.Redirect it!
Redirect oldpage.html

8.Block visits or leeches from specific referers!
RewriteEngine on
RewriteCond %{HTTP_REFERER} site-to-block\.com [NC]
RewriteCond %{HTTP_REFERER} site-to-block-2\.com [NC]
RewriteRule .* - [F]

9.Stop a file from being viewed!
# mycontacts.txt cannot be accessed by any means:
<files mycontacts.txt>
order allow,deny
deny from all

10.Password-protect a directory!

1 comment: