technology and zen of life

“A heisenbug (named after the Heisenberg Uncertainty Principle) is a computer bug that disappears or alters its characteristics when an attempt is made to study it.”

htaccess tips and tricks

If you have a webhosting you have to have basic know how of tips and tricks you can do with htaccess. So here is a list of basic actions that can be done via htaccess and how to use them.


Disable Directory Browsing

Options All -Indexes

Enable Directory Browsing
In the remote case that you want to list your directories:

Options +Indexes
## block a few types of files from showing
IndexIgnore *.wmv *.mp4 *.avi

Customize Error Messages

ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html

Change Default Page

The pages are searched in the order specified.

DirectoryIndex index.html index.htm index.php fallback.html

Forward all to (Good for removing duplicate links)

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.techmonks\.net$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

Redirect to a new URL

Redirect oldlocation.html
Redirect /subdomain

Disable access to images from other websites (Hot linking)

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?*$ [NC]
RewriteRule \.(gif|jpg)$ - [F]

You can also replace it with a static/warning image:

RewriteRule \.(gif|jpg)$ [R,L]

Allow only local users

order deny,allow
deny from all
allow from (replace with local subnet)

Block Users from accessing the site

order deny,allow
deny from (deny subnet / ip)
deny from
allow from all

Stop .htaccess (a file) from being viewed

order allow,deny
deny from all

Grant CGI (perl) Access in a directory

Options +ExecCGI
AddHandler cgi-script cgi pl

Enable Gzip compression


AddOutputFilterByType DEFLATE text/html text/xml text/css application/x-javascript application/javascript



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.


The views expressed on this blog are personal. We do not claim to be a representative voice of the views of any organisation whatsoever. We are not responsible for the content present on the blogs to which we have linked.Views expressed are solely that of the author and does not reflect a collective opinion of contributors.
%d bloggers like this: