Using a .htaccess file to block .htaccess files being loaded to subdirectories

.htaccessapache-2.2lamp

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

Best Answer

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.