Thursday, June 12, 2008

.htaccess tutorial

1) Password Protected Directory

AuthUserFile /your/directory/here/.htpasswd
AuthGroupFile /dev/null
AuthName "Secure Document"
AuthType Basic
require user username

2) Password Protectection for a file


AuthName "Restricted File"
AuthType Basic
AuthUserFile /user/home/www/directory/.htpasswd
require valid-user

3) Protecting the file types


AuthName "Restricted"
AuthType Basic
AuthUserFile /user/home/www/directory/.htpasswd
require valid-user

4) Error Documents

ErrorDocument 400 /error/badrequest.htm
ErrorDocument 401 /error/authorisereqd.htm
ErrorDocument 403 /error/forbidden.htm
ErrorDocument 404 /error/filenotfound.htm
ErrorDocument 500 /error/servererror.htm

5) Redirecting Pages

Redirect /old-directory/oldpage.htm http://domain.com/new-directory/newpage.htm

Redirect /old-directory http://domain.com/new-directory/

6) Default page

DirectoryIndex default.htm

DirectoryIndex default.htm home.cgi sadass.pl otherfile.html

7) Add types and Add handler

AddType text/html .html
AddHandler server-parsed .html
AddHandler server-parsed .htm

8) Block Users by using IP


order deny,allow
deny from 123.456.789.000
deny from .domain.com
allow from all

No comments: