.htaccess files can be used to specify security restrictions, give customized error responses, rewriting URL's and other useful functions.
They can be written with Notepad or another text editor. They should be placed in the root if you want it to affect the entire website (/.htacces) or a specific folder to only affect a certain folder (/content/html/images/.htaccess - this will only affect the images folder). To allow the FTP client to see the .htaccess file, you should have it configured to see 'hidden files'.
Here are some examples of some commonly used .htaccess:
To deny directoy browsing:
IndexIgnore *
'*' is a wildcard which means no files will be dispalyed. You can also prevent particular files from being displayed:
IndexIgnore *.gif *.jpg
To allow directory browsing:
Options +Indexes
To redirect files:
Redirect permanent /OldDir/old.html /NewDir/new.html
Redirect permanent /Oldfile.htm /Newfile.htm
To redirect to a different domain:
#Options +FollowSymlinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yoursite.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.yoursite.com$
RewriteRule (.*)$ http://www.thenewdomain.com/$1 [R=301,L]
To prevent hot linking of images from your website:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?your-domain.com/.*$ [NC]
RewriteRule .(gif|jpg)$ - [F]
To create your own error pages:
ErrorDocument 'Errorcode' /errors/errordoc.html
eplace 'Errorcode' with the three digit error code you want it to refer to.