The .htaccess file
The Apache server is probably the most widely used for hosting web sites, and is fairly easy to configure in a wide variety of different ways through the use of one or more .htaccess configuration files.
The .htaccess file, if configured for use on the server, can do a whole manner of things. One of the most useful applications it has is for allowing a site owner to customise their error messages, not only for each different type of error, but also for each different directory if they wish. Other uses include invisibly using it to redirect users to another page without the use of a meta refresh, or even to restrict access to areas of the site (which is useful for any kind of members section).
Using the .htaccess file
What makes the .htaccess file the most flexible way of configuring Apache is the fact that it allows the webmaster to edit the way their individual site responds to file requests, on a directory by directory basis if necessary, without having to stop or restart the server.
The server will look for .htaccess files in directories along the path of a file before processing the request. Assuming that it works backwards along directories along a path, any processing rules found in the local directories will overwrite any more general rules found in their parent directories when there are conflicts. This overwriting of inherited attributes allows you to apply the more general site wide behaviours in the root folder of your site, while applying more specific rules to those directories that need it.
Unfortunately, there is the inevitable degradation in performance when you use .htaccess, so you should take this into consideration before you go overboard with your use of them. If you have full control of the server, it might be a better idea to set certain settings in the actual server configuration file. It is also worthwhile remembering that the host may have limited exactly what you can do through the use of .htaccess because it would be more efficient to configure general behaviour on a server rather than site basis.
Creating a .htaccess file
There is no special program that you need to be able to edit or create a .htaccess file, since it is simply a normal text file containing a list of instructions that Apache will understand. You can create a new text file in the usual way and edit it in a text editor (a simple editor is recommend to help keep the file clean of unnecessary code).
When you come to save your file for the first time, you should be able to force your text editor to rename it correctly by surrounding the name in "double quotes". If you are having problems, you can also name it something obvious such as htaccess.txt and then rename it once it is uploaded to the server.
FTP and .htaccess
When you come to upload your .htaccess files, you should be aware that it makes a difference as to where you put them. A single .htaccess file in the root directory will have an effect on the entire site, but it can be over-ridden by putting a different .htaccess file in your sub directories. The server will look for a .htaccess file in the same directory as the error first, if it can't find one it will move one directory back until it finds one. Of course, if it doesn't find one then it will just use either the server's or browser's default error page (depending on server setup).
It is recommended that you upload your .htaccess file in ASCII rather than binary format, to ensure that information in the file is not corrupted. Be aware that most FTP programs do not show hidden files by default, so if you upload a correctly named file then you could be forgiven for thinking that you hadn't uploaded it. Similarly, if you need to rename it on the server, the file will appear to disappear from view even when it is still there. If you want more information on how to view and work with these files, please see my advanced ftp tutorial, which makes use of WS_FTP LE.
.htaccess maintenance
Although you probably will not need to change the actual contents of your .htaccess file very often, the fact that it is a hidden file on the server does not make the job of maintenance any easier. I would recommend that you keep a copy of any .htaccess files along with the local copy of your site this way you can make changes offline and upload it when you are ready to apply the changes (you do have a local copy of your site, don't you?).
The main advantage of keeping a local copy is that you can easily see the current settings (assuming that you only change the file when you add or change any settings). This is useful because you do not run the risk of removing any settings that you might have forgotten that you put in your .htaccess file.
Getting Started
If you are unfamiliar with Apache and its configuration files, then you might find the idea of tweaking your server via .htaccess a daunting prospect. While the contents of the file can sometimes be difficult to interpret, there are a series of rules that you can follow when configuring the server in this way.
So why not give it a go? Have fun experiementing with some of the more advanced features of your Apache server!
