.htaccess files are used by apache to enable the web developer to specify the server configure for the folder that the .htaccess file recides in.
.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.
.htaccess is a very powerful way to control the server on a folder-to-folder basis. But if possible, it is advised to use the main server configuration file(httpd.conf). The apache server can be configured in a folder by folder fashion in the <directory> section of the main configuration file. There are two disadvantages of using .htaccess file rather than the main configuration file(httpd.conf) are...
Disadvantages of .htaccess
- Apache will look for .htaccess file in every parent folder of the file whenever a request is made for the file. So if you turn on the .htaccess file support, there will be a performance hit - even if you don't use them - as apache will search for the files anyway.
- Anyone with access to the document root(through FTP or Shell Access) will be able to modify the server configuration. You don't want to do that.
Advantages of .htaccess
If we have a large site with a lot of directory based options, the
httpd.conf file will soon become a big and unmaintainable file. Putting the configuration of each directory in that directory(as in the case of .htaccess) is a more maintenance friendly solution.
You may not have access to the main server configuration file. If your site is hosted on a shared server(like mine is), this is often the case. In such cases .htaccess is a life saver.
If you make a change to the
httpd.conf, you must restart Apache for it to take effect. On the other hand,
.htaccess file have no such problems.
More on .htaccess in the next post.