.htaccess Cheat Sheet
.htaccess | Tutorials & Resources
.htaccess (Hypertext Access) is the default name of Apache’s directory-level configuration file. It provides the ability to customize configuration directives defined in the main configuration file. The configuration directives need to be in .htaccess context and the user needs appropriate permissions.
Enable Directory Browsing
Options +Indexes
Disable Directory Browsing
Options All -Indexes
Block Files from showing in Directory Browsing
IndexIgnore *.rmvb *.mp3 *.avi
Customize Error Messages
ErrorDocument 403 /forbidden.html
ErrorDocument 404 /notfound.html
ErrorDocument 500 /servererror.html
Get SSI working with HTML/HTM/SHTML
AddType text/html .html
AddType text/html .shtml
AddHandler server-parsed .html
AddHandler server-parsed .shtml
AddHandler server-parsed .htm
Change Default Page
DirectoryIndex myhome.htm index.htm index.php
Block Users from accessing the site
<limit GET POST PUT>
order deny,allow
deny from 202.54.122.33
deny from 8.70.44.53
deny from .spammers.com
allow from all
</limit>
Allow only LAN users
order deny,allow
deny from all
allow from 192.168.0.0/24
Redirect Visitors to New Page/Directory
Redirect oldpage.html http://www.domainname.com/newpage.html
Redirect /olddir http://www.domainname.com/newdir/
Block site from specific referrers
RewriteEngine on
RewriteCond %{HTTP_REFERER} site-to-block\.com [NC]
RewriteCond %{HTTP_REFERER} site-to-block-2\.com [NC]
RewriteRule .* - [F]
Block Hot Linking/Bandwidth hogging
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]
RewriteRule \.(gif|jpg)$ http://www.mydomain.com/dontsteal.gif [R,L]
Stop .htaccess (or any other file) from being viewed
<files file-name>
order allow,deny
deny from all
</files>
Avoid the 500 Error
AddDefaultCharset utf-8
Grant CGI Access in a directory
Options +ExecCGI
AddHandler cgi-script cgi pl
SetHandler cgi-script
Change Script Extensions
AddType application/x-httpd-php .gne
Use MD5 Digests
ContentDigest On
The CheckSpelling Directive
CheckSpelling On
Save Bandwidth
<ifmodule mod_php4.c>
php_value zlib.output_compression 16386
</ifmodule>
Turn off magic_quotes_gpc
<ifmodule mod_php4.c>
php_flag magic_quotes_gpc off
</ifmodule>


(4 out of 5)















One Comment, Comment or Ping
Wolf50
Have you made your resolutions yet? ,
Oct 11th, 2009
Reply to “.htaccess Cheat Sheet”