At work, every project has an .htaccess
file containing at the least some mod_rewrite
rules. This way, all I need to do to run a project is check it out of version control. I don’t need to modify my local Apache configuration.
But turning this option on and allowing .htaccess
files may be a performance hit. More specifically, enabling the AllowOverride
option in Apache is a performance hit. The Apache docs sums up the problem best:
“Wherever in your URL-space you allow overrides (typically
.htaccess
files) Apache will attempt to open.htaccess
for each filename component. For example,
1 2 3 4 DocumentRoot /www/htdocs <Directory /> AllowOverride all </Directory>and a request is made for the URI
/index.html
. Then Apache will attempt to open/.htaccess
,/www/.htaccess
, and/www/htdocs/.htaccess
.”
So I disabled all .htaccess
files in production, and inserted each file’s individual mod_rewrite
rules into the main Apache config file. After a quick Apache Bench run, one project looked around 3% faster. Note that there are a few other useful optimizations on that page.
2 Comments to 'Tip Of The Day: Removing .htaccess'
June 18, 2009
Good tip, I’ve used it for awhile. Down side: any changes require a restart (albeit graceful) of Apache. Not recommended for Apache servers with a fair number of domains, or for shared hosting servers. Maintainability goes down a bit too, requiring all developers to now have root access or go through change management to modify the Apache config.
Is it worth the 3%? Who knows.
My reco: switch to nginx/lighttpd and ditch Apache. It’s a hog.
June 19, 2009
Good point re: management. Of course, for me, change management means, I make the change. Hasn’t been too bad.
Switching to nginx is currently on the if-it-aint-broke-dont-fix-it list.