With a little side of applesauce...

Thursday, February 8, 2007

Apache - Multiple .htaccess files

We just found out that Apache merges multiple .htaccess files, by adding files as an array to the AccessFileName directive:

AccessFileName .htaccess .userconfig


This allows us to give write access to .userconfig, while keeping our authentication configuration in the .htaccess file, (which is Denied in the httpd.conf). Here is an example of the contents of a .userconfig file:

RewriteEngine On
RewriteRule ^(.*)$ http://www.example.com


This will merge into the contents of the .htaccess file, which could be something like:

<LimitExcept GET POST>
require group adminGroup
</LimitExcept>

3 comments:

Anonymous said...

didn't work for me :(
only the first existing htaccess file is beeing used (apache2.2)

Shannon Eric Peevey said...

Looks like it only uses the first matched file now:
http://httpd.apache.org/docs/2.2/mod/core.html#accessfilename

This posting may have been for apache 1.3, (I don't remember :P ).

Take care!

Shannon Eric Peevey said...

Actually, looking back on the 1.3 docs, it says the same thing. I'm guessing that this was probably possible on a version of 2.0, but may have never been officially supported.