Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

(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

1 Answer 1

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/.htaccess

/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

 
discard

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.