.htaccess , Whats is it?
According to Apache:
.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
‘Directives’ usually refer to the commands that are contained in the .htaccess files, which control or modify your server’s various behaviours. Many free and paid web hosts permit you to change and modify your .htaccess files but remember if you have a website running on Yahoo Geo Cities,Goolge sites or freewebs then this article is meaningless for you cause they dont allow access to .htaccess files
What can you do with .htaccess?
.htaccess can be used in many different creative ways , but its most common usage is for:
- Setting up custom 404 error pages
- Enable/Disable directory browsing
- Change default homepage for a directory
- Block certain users from accessing your site
- Block specific refferers
- Prevent certain files from being viewed
- Block Hotlinking
How to create one?
Create a text file from any text editor, Note Pad,Text Pad and save it as .htaccess ( remember the period before htaccess and no .txt extension ).
Upload it in your home directory…The rules in .htaccess file apply to all the sub directories in your files directory
Doing some cool stuff
Now here comes the real thing…
To enable your server to use a custom 404 file not found page for broken links or URL typos…
include the following code in your .htaccess file:
' [code lang="php"] #The page notfound.html should be in the same directory as your .htaccess ErrorDocument 404 /notfound.html #Alternatively you can specify just raw html to be used instead of a page ErrorDocument 404 "<h1>yikes! that page passed away a while ago...</h1>" [/code] '
Enable / Disable directory browsing
## Block some specific file types from showing
IndexIgnore *.avi *.mp3 *.pdf
Change directory homepage
##the pages are used in order
DirectoryIndex myhomepage.html index.html index.php
Block some users from accessing your site
deny from 184.108.40.206
deny from 220.127.116.11
deny from .hackers.com
allow from all