Whatever you wanto call this, a cheat sheet, a real thin manual, or anything, we simplify the use of .htaccess as much as possible and make it do more for you with less hassle.
- Unify example.com and www.example.com!
# Use a 301 redirect from example.com to www.example.com to tell SEs that the 2 domains are the same thing so there's no PageRank leakage. RewriteEngine On RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301]
- Block spammers!
# This blocks xxx.xxx.xxx.xxx and *.example.com from accessing your site. <limit GET POST PUT> order deny,allow deny from xxx.xxx.xxx.xxx deny from .example.com allow from all </limit>
- Change default page!
# The order is followed as specified: DirectoryIndex default.htm default.php index.html index.php
- Enable directory browsing!
Options +Indexes # block a few types of files from showing: IndexIgnore *.wmv *.mp4 *.avi
- Disable directory browsing!
Options All -Indexes
- Customize error messages!
ErrorDocument 403 /forbidden.html ErrorDocument 404 /notfound.html ErrorDocument 500 /servererror.html
- Get SSI working with HTML/SHTML!
AddType text/html .html AddType text/html .shtml AddHandler server-parsed .html AddHandler server-parsed .shtml
- Redirect it!
Redirect oldpage.html http://www.domainname.com/newpage.html
- 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]
- Stop a file from being viewed!
# mycontacts.txt cannot be accessed by any means: <files mycontacts.txt> order allow,deny deny from all </files>
- Change script extensions!
# anyfile.kv will be treated like a PHP script: AddType application/x-httpd-php .kv # anyfile.kvcgi will be treated like a CGI script: AddType application/x-httpd-cgi .kvcgi
No comments:
Post a Comment