As a web developer we all have all used our htaccess file for one thing or another. However, many developers are not aware of everything an htaccess file can do for them. I have provided the following cheatsheet as a reference for a handful of these functions.
If you have some additional tips that should be added to this list, please feel free to post them in the comments and I will add them to the resource.
Enable Directory Browsing
Options +Indexes
## block a few types of files from showing
IndexIgnore *.wmv *.mp4 *.avi
Disable Directory Browsing
Options All -Indexes
Custom Error Message Pages
ErrorDocument 403 /somePage1.html
ErrorDocument 404 /somePage2.html
ErrorDocument 500 /somePage3.html
Change Default Page Order
DirectoryIndex myhome.htm index.htm index.php
Ban User IPs
order deny,allow
deny from 123.456.789.00
deny from 123.456.789.00
deny from .someDomain.com
allow from all
Block Visitors From Specific Referring Sites
RewriteEngine on
RewriteCond %{HTTP_REFERER} site-to-block.com [NC]
RewriteCond %{HTTP_REFERER} site-to-block-2.com [NC]
RewriteRule .* – [F]
Block Specific Search Spiders From Site
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^searchbot1 [OR]
RewriteCond %{HTTP_USER_AGENT} ^searchbot2 [OR]
RewriteCond %{HTTP_USER_AGENT} ^searchbot3
RewriteRule ^(.*)$ http://www.yourSite.com/goAway.htmlOR
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} ^searchbot1 [OR]
RewriteCond %{HTTP_USER_AGENT} ^searchbot2 [OR]
RewriteCond %{HTTP_USER_AGENT} ^searchbot3
RewriteRule ^(.*)$ http://www.someOtherWebsite.com/ [R, L]
I have also written a post on the use of 301 Redirects for SEO
















Pingback: Pipe Ten Web Hosting Resource » Blog Archive » .htaccess cheat sheet
Pingback: ズゴックNo.1 - links for 2008-11-05
Pingback: Tagz | "htaccess Cheatsheet | marketing . web . design" | Comments
Pingback: .htaccessã«é–¢ã™ã‚‹è¦šãˆæ›¸ã - IDEA*IDEA ~ 百å¼ç®¡ç†äººã®ãƒ©ã‚¤ãƒ•ãƒãƒƒã‚¯ãƒ–ãƒã‚°