27 November 2010

.htaccess file !!!!!!Create your own custom error Pages

Today through this Post of mine, I will make you aware of a very important file which is commonly used by web developers or web administrators named “.htaccess file”.
Now one of the obvious question that comes into our mind is
What is .htaccess file?
It is just a text file that consists of a few simple instructions and has power to improve your website, through this file you can change settings of your web servers, even you can also have your own custom 404 error pages.
(Please refer Wikipedia to know more about 404 error pages)

.htaccess can do following things for you

1:- Password protection of folders for eg admin folder.

2:-Banning users with certain IP addresses.

3:- Only allowing users with certain IP addresses etc.

The next question that can come in your mind is Will my Host support it?
There is a general rule for this, if your server runs on UNIX or LINUX, or any other version of Apache web server it will support .htaccess, but in most cases it depends on your hosts. Many hosts support .htaccess file but don’t allow users to use it and many hosts don’t, However you can check yourself also that whether it supports .htaccess file or not, for that just upload your own .htaccess file and see if it works or simply asks your webhost.

Brief description of various functions of .htaccess file.

1:- Custom Error Pages

The very first use of the .htaccess file is that you can also create our own custom error pages i.e. instead of using host's error pages we can show our own error pages.

More specifically, say if a user try to access a certain file which is currently not available, then we can create our own file say ‘manish.html’ which we want to show at that time, just upload it to root directory of your website and add the following code to .htaccess file and upload it to web server

ErrorDocument 404 /manish.html

Note :To know more about Custom Error Pages, Please refer Wikipedia.

2:- Deny/Allow Certain IP Addresses

In some situations, you may want to only allow people with specific IP addresses to access your site

So you can block an IP address by using:

deny from

where is the IP address.

You can allow an IP address by using:

allow from

where is the IP address.

These are few common uses of .htaccess file which i have learned so far, still there is still one important function of .htaccess file i.e. Password protection of certain folders which I will post in my next post so stay tuned. :)

Please leave your comments if you like this