(Centos 5.2, Apache 2.2.8)

How do .htaccess files work when one is in a subdirectory of another?

For example, if I put a .htaccess in /var/www/html/images that only allows access to *.jpeg files, and a .htaccess in /var/www/html/images/subdir that allows access to everything which will take precedence for files in /var/www/html/images/subdir?

If the child .htaccess takes precedence is there any way to set the parent .htaccess to not allow the settings in it to be overridden by child directories?


The lower .htaccess rules will override parent directories' .htaccess files. Apache climbs up the directory tree from root and builds the configuration tree from the .htaccess found in each directory, and later changes to the configuration override prior settings.


/var/www/html/images/.htaccess overrides

/var/www/html/images/subdir/.htaccess overrides

I do not think that .htaccess files can restrict lower .htaccess files, but you might think about disabling .htaccess files (AllowOverride None) and doing your configuration at the server level, or create a dummy .htaccess file in the lower directory and restrict it's modification with file permissions.

  • AllowOverride None for just one directory may be perfect... otherwise there's a potential attack of create directory/put .htaccess file in it/put malicious PHP file in it. It would be a lot nicer if the website code could be trusted to propelry filter uploads. :-)
    – DrStalker
    Feb 2 '11 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.