Friday, July 30, 2010

Apache .htaccess file

.htaccess files (or "distributed configuration files") provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.

Default directory page

DirectoryIndex filename.html index.cgi index.pl default.htm


Protect access of .htaccess file


order allow,deny
deny from all


Customized error documents:

ErrorDocument 400 /errors/badrequest.html
ErrorDocument 401 /errors/authreqd.html
ErrorDocument 403 /errors/forbid.html
ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 /errors/serverr.html


Blocking users by IP

order allow,deny
deny from 123.45.6.7
deny from 012.34.5.
allow from all


Redirects

Redirect /olddirectory/oldfile.html http://yoursite.com/newdirectory/newfile.html


Add MIME Types

AddType application/x-shockwave-flash swf


Protec againts hot linking of images and other file types

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


Preventing Directory Listing

IndexIgnore *
IndexIgnore *.bmp *.gif

No comments:

Post a Comment