Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

(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?

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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