5.11. Using .htaccess Files

We experimented with putting configuration directives in a file called ... /htdocs/.htaccess rather than in httpd.conf. It worked, but how do you decide whether to do things this way rather than the other?

The point of the .htaccess mechanism is that you can change configuration directives without having to restart the server. This is especially valuable on a site where a lot of people are maintaining their own home pages but are not authorized to bring the server down or, indeed, to modify its Config files. The drawback to the .htaccess method is that the files are parsed for each access to the server, rather than just once at startup, so there is a substantial performance penalty.

The httpd.conf (from ... /site.htaccess) file contains the following:

User webuser Group webgroup ServerName www.butterthlies.com AccessFilename .myaccess ServerAdmin sales@butterthlies.com DocumentRoot /usr/www/site.htaccess/htdocs/customers ErrorLog /usr/www/site.htaccess/logs/customers/error_log TransferLog /usr/www/site.htaccess/logs/customers/access_log ScriptAlias /cgi-bin /usr/www/cgi-bin <VirtualHost sales.butterthlies.com> ServerAdmin sales_mgr@butterthlies.com DocumentRoot /usr/www/site.htaccess/htdocs/salesmen ServerName sales.butterthlies.com ErrorLog /usr/www/site.htaccess/logs/salesmen/error_log TransferLog /usr/www/site.htaccess/logs/salesmen/access_log ScriptAlias /cgi-bin /usr/www/cgi-bin #<Directory /usr/www/site.htaccess/htdocs/salesmen> #AuthType Basic ...

Get Apache: The Definitive Guide, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.