Apache’s AllowOverride option, which determines the control allowed via an htaccess file in a directory, can be an irritating little setting when you forget about it.

This time around it caught me because I thought I had set it correctly and couldn’t figure out why changes to htaccess weren’t taking effect. Turns out there was an overlap in the Apache config file. Lesson learned, if an htaccess configuration setting just won’t work, check the AllowOverride function in httpd.conf.

And for testing purposes, it’s relatively easy to create a duplicate directory of a public site, then play around with htaccess changes on the duplicate site and simply copy the “right” settings back over to the production site. Just be sure that both <Directory> entries in httpd.conf have the same AllowOverride settings. Below is a simple sample Directory entry for httpd.conf (or under sites-enabled in Ubuntu).

Alias /test "/var/www/test"
<Directory "/var/www/test">
  Options Indexes FollowSymLinks
  AllowOverride All
  Order allow,deny
  Allow from all
</Directory>

With that inserted in httpd.conf you can now add directives to the htaccess file in the directory root (e.g., /var/www/test/.htaccess) and those directives will “override” the default Apache configuration. The one I was working on was a mod_rewrite entry to enable clean URLs on a website, so I needed to insert those rewrite rules into the htaccess file, like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /test/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /test/index.php [L]
</IfModule>