The .htaccess file

Quotation Graphic  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....  Quotation Graphic

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 »

Originally Published: Tue 23rd Dec, 2003
The author, Rosemarie Wise, is a self proclaimed "web enthusiast" who set up her site, Web Site Owner to share her experiences of being a site owner.

Script Installation Articles Index  Back to Articles

SoftbizScripts.com - Great PHP Scripts to launch high earning websites
What's New?

Support Desk Script

best autoresponder script The BEST Autoresponder.

Affiliate Link Encryptor!



Link Machine, Link Directory Script


Green Web Hosting
Sustainable Living