1

Ok, lets say I have a normal text file on my server in the document root. Suppose the folder on the system assigned to document root is /doc. The filename will be a.txt (stored as /doc/a.txt) The folder is setup to allow Apache configuration from a .htaccess file.

This is my main server httpd.conf file relevant to the /doc folder:

<Directory "/doc">
Options -Indexes +FollowSymLinks -multiviews
AllowOverride All
</Directory>

Assuming my public domain is http://www.example.com, I request http://www.example.com/a.txt to download the file.

I then look behind the scenes on the server side with strace.

It looks normal when Apache wants to load /doc/.htaccess (.htaccess from the document root folder), but it's also trying to load /doc/a.txt/.htaccess as well.

Why would Apache append .htaccess to the entire resource and request it to exist on the server? And how do I disable only that scan for .htaccess?

For clarity: searching for /doc/.htaccess is fine, but searching for /doc/a.txt/.htaccess is unacceptable.

1 Answer 1

0
<Directory "/doc">
:
AllowOverride All
</Directory>

This allows .htaccess overrides for the entire file-path. This includes the directory /doc and all subdirectories.

An inefficiency of allowing .htaccess overrides is that the .htaccess file is scanned for in all possible subdirectories along the URL/file-path.

The scanning for .htaccess files occurs very early, so when you make a request for /a.txt it doesn't yet know whether that request maps to a directory or not.

You could perhaps avoid the additional scanning of "subdirectories" and restrict the use of .htaccess files to the root only by including an additional <Directory> container that prevents .htaccess overrides for /doc/<something>/ and everything below. For example:

<Directory "/doc/*">
AllowOverride None
</Directory>

This should go after your existing <Directory "/doc"> container.

Or, use a regular expression instead:

<DirectoryMatch "^/doc/.">
AllowOverride None
</Directory>
1
  • I wish there was away one can define such a rule in .htaccess without the need to restart apache
    – mike_s
    Commented Oct 17 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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