General
information
Filename .htaccess
Location directory where modified rule has to be applied
/ means to whole website
permission rwxr r use chmod 0744
Custom Error documents
Standard HTTP
Error Codes
400 - Bad Request
401 - Authorization Required
403 - Forbidden
404 - Not Found
500 - Internal Server Error
503 - Service Unavailable
Aim
To Create your own error documents than allowing the browser default
Assumptions
Error file placed in /errors directory and are php files.
.htaccess Entry
ErrorDocument 404 /errors/404.php
Redirecting Request
Aim
You have a new server with upgraded features and you want to
direct clients to that site.
Assumptions
/directory contents has been shifted to a different server namely
http;//www.mydirectory.com/
modification done on /directory .htaccess
.htaccess Entry
Redirect Permanent /directory http://www.mydirectory.com/
(in your old server .htaccess)
There four different option in the place of permanent to be used
1 permanent - the resource has moved permanently
2 temp - it has temporarily moved elsewhere
3 seeother - the resource has been replaced
4 gone - it has been permanently removed
Showing Directory contents
Aim
Not to display directory content where index files are not present.
Assumptions
/.htaccess is modified to prevent website wide display of directory.
.htaccess Entry
IndexIgnore *
Multiple
directory indexes
Aim
You want use custom file 'search.php' as directory/website index apart
from normal index.htm
Assumptions
/.htaccess is your htaccess file.
.htaccess Entry
DirectoryIndex search.php index.htm
(you can add more)
Deny request
from certain ip address
Aim
Deny file request from certain IP address
Assumptions
/.htaccess is your htaccess file.
.htaccess Entry
deny from 169.125.64.32
(ip is Only an example)
Serverside inclde for the
website
Aim
Enable Servierside include for the entire website
Assumption
.htaccess is in your web root directory
.htaccess Entry
Options +Includes
AddType text/html shtml
AddHandler server-parsed shtml
User
authentication
Aim
User should login to access certain directories
Assumption
.htaccess in directory /auth so that user have to login while accessing
http://www.mysite.com/auth
htaccess entry
AuthType Basic
AuthName "Password Required"
AuthUserFile /www/passwds/passwd
AuthGroupFile /www/passwds/group
Require Group admins
User auth require more details, for generating passwd file
you can do the follwing .
# htpasswd -c /www/passwds/passwd coolfellow
New password: mypassword
Re-type new password: mypassword
Adding password for user rbowen
The group file content contains space seperated user names with
following syntax
admins: coolfellow badguy neponte
Change of scripting
language and old links
Aim
You are changing your scripting language to php and you want to
preserve
earlier .htm link to work in same way
Assumption
.htaccess in your webserver root directory
.htacces entry
RewriteRule ^(.*)\.htm$ $1.php [nc]
Rewrite rule says ^(.*) filename before extension remains same for php
also and refer php whenever a htm file is accessed.when ever
you specify RewriteRule use RewriteEngine on the top of file
Cgi Redirect
Aim
You want hide real cgi scripts from enduser.
Assumption
.htaccess in root directory of your webserver
.htaccess Entry
RewriteRule ^list/(.+)/(.+)/(.+)/
/cgi-bin/search.pl?arg1=$1&arg2=$2&arg3=$3 [nc]
Display
different files for different browsers
Aim
To Display different files for different browsers for browser
compatibility
Assumption
.htaccess in root directory of your webserver
.htaccess Entry
RewriteCond %{HTTP_USER_AGENT} ^Mozilla.*
RewriteRule ^/$ /mozilla/index.php [L]
RewriteCond %{HTTP_USER_AGENT} ^Lynx.*
RewriteRule ^/$ /Lynx/index.php [L]
RewriteRule ^/$ /index.php [L]
You moved your home dir
Aim
To access the moved home directory from external links
Assumption
.htaccess in root directory of your webserver
.htaccess Entry
RewriteRule ^/$
/changedroot/www/ [R]
Author
Constantine
|