· apache optimisation

No More .htaccess

Why should you disable .htaccess

Performance and security. For this article I’ll focus on the performance overhead. Surprisingly this is not only best practise but also in the official documentation from Apache. See here and here

Here’s an except from the Apache documentation :

You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a . htaccess file is better set in a Directory block, as it will have the same effect with better performance.

In general, you should only use .htaccess files when you don’t have access to the main server configuration file. There is, for example, a common misconception that user authentication should always be done in .htaccess files, and, in more recent years, another misconception that mod_rewrite directives must go in .htaccess files. This is simply not the case. You can put user authentication configurations in the main server configuration, and this is, in fact, the preferred way to do things. Likewise, mod_rewrite directives work better, in many respects, in the main server configuration.

What to takeaway from the Apache documentation

.htaccess files are a great example of how flexible and awesome Apache server really is but unfortunately they are being used when users have access to Apaches main configuration files. .htaccess files are for those on shared hosting plans who can not edit the server config file. Using .htaccess files causes a performance hit, even if they are empty as they are reloaded on every request. Everything should be moved to Apaches main config file and you should disable .htaccess completely. Disabling .htaccess and using the Apache config

To disable .htaccess completely you need to set the AllowOverride directive to none:

AllowOverride None

and then move any directives to your vhost configuration file.

<VirtualHost *:80>
 ServerName aaron.mehar.me
 DocumentRoot /var/www/html/

 <Directory />
  AllowOverride none
 </Directory >

 Options -Indexes FollowSymLinks

 <Directory /var/www/html>
  # BEGIN WordPress
  <IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /
   RewriteRule ^index\.php$ – [L]
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule . /index.php [L]
  </IfModule>
   #END WordPress
  </Directory>
</VirtualHost>
  • LinkedIn
  • Tumblr
  • Reddit

Aaron Mehar

Berkshire, UK