The .htaccess performance penalty

Direct from Apache's documentation:

When AllowOverride is set to allow the use of .htaccess files, Apache will look in every directory for .htaccess files. Thus, permitting .htaccess files causes a performance hit, whether or not you actually even use them! Also, the .htaccess file is loaded every time a document is requested.

So, why use them?

If your answer is because your SEO-friendly WordPress permalinks won't function without them, then you've come to the right place!

Just about anything that can be done in an .htaccess file can be performed within a <Directory> block within your httpd.conf file. Since you already have a <Directory> block for your site, containing the AllowOverride directive, you can simply remove AllowOverride, and append your rewrite directives in it's place.

Example:

<Directory /var/www/html/mysite_com>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</Directory>

Why follow me on Twitter?

  • I tweet about new technologies, services or libraries I find interesting
  • Yeah, sometimes I'll post a pet-peeve or rant about something trivial
  • If I discover something that made my web development life easier, I share it
  • I'll shout out any handy tip that I think might be useful to other devs


Tagged , .

Updated: 2012-01-29

Phil LaNasa follow us in feedly