I was discussing (well twitting is more appropriate) with my friend Arnaud about .htaccess files and why they should not be used.
To be quick, using .htacess files is not good at all for disk performance because Apache will hit the disk for each HTTP request, so when the site is on production you can easily imagine this can quickly be an issue if you use those files.
But let’s have a look at how it actually work on the system.
Remember, for each HTTP request Apache will look on your file system if it finds a .htaccess file. So if we create the following virtual web application :
webproject |-- cache |-- design | |-- css | |-- html | |-- images | `-- javascript `-- src |-- php `-- python
With the following directive in your Apache configuration file (wether a VirtualHost or not) :
<Directory "/path/to/webproject/"> AllowOverride All [....] </Directory>
Now let’s have a look at how Apache handle AllowOverride on the Operating System, what happens if I visit the ‘webproject/src’ directory ?
Calling http://localhost/webproject/src generated the following system calls
1679/0x97c9998: open("/Users/jerome/work/www/.htaccess\0", 0x0, 0x1B6) = -1 Err#2
1679/0x97c9998: open("/Users/jerome/work/www/webproject/.htaccess\0", 0x0, 0x1B6) = -1 Err#2
1679/0x97c9998: open("/Users/jerome/work/www/webproject/cache/.htaccess\0", 0x0, 0x1B6) = -1 Err#2
1679/0x97c9998: open("/Users/jerome/work/www/webproject/design/.htaccess\0", 0x0, 0x1B6) = -1 Err#2
1679/0x97c9998: open("/Users/jerome/work/www/webproject/src/.htaccess\0", 0x0, 0x1B6) = -1 Err#2
1679/0x97c9998: open("/Users/jerome/work/www/webproject/src/python/.htaccess\0", 0x0, 0x1B6) = -1 Err#2
1679/0x97c9998: open("/Users/jerome/work/www/.htaccess\0", 0x0, 0x1B6) = -1 Err#2
1679/0x97c9998: open("/Users/jerome/work/www/webproject/.htaccess\0", 0x0, 0x1B6) = -1 Err#2
1679/0x97c9998: open("/Users/jerome/work/www/webproject/src/.htaccess\0", 0x0, 0x1B6) = -1 Err#2
1679/0x97c9998: open("/Users/jerome/work/www/webproject/src/php/.htaccess\0", 0x0, 0x1B6) = -1 Err#2
As you can see Apache looked for the .htaccess file for each directory I had to browse in order to go to the webfolder/src directory.
That is a simple example, but if you have a much more complex directory structure and a lot of traffic I guess you can imagine how much Apache is going to hit the disk in order to find a .htaccess file.
So in order to avoid that it is always recommended to configure everything in VirtualHosts and to avoid .htaccess files.
‘Hope that helped a bit












