When you specify just the bare directory mod_dir issues an internal subrequest for the DirectoryIndex (which I assume is configured to serve index.html
in your case). "The problem" is that the <Files>
directive is first processed before the subrequest occurs. But before this subrequest occurs the filename that the <Files>
directive matches against has not yet been resolved; it is empty! So, we need to match against an empty filename.
However, once the subrequest for index.html
(the DirectoryIndex) has occurred then the <Files>
container is reprocessed (in a .htaccess
context), but this time the filename has resolved to index.html
. So, we need to match against index.html
as well!
This can be accounted for by either having two <Files>
containers. For example:
<Files "">
Order allow,deny
Allow from all
</Files>
<Files "index.html">
Order allow,deny
Allow from all
</Files>
Or (preferably) combining these into a single <FilesMatch>
container (that accepts a regex as the argument). For example:
<FilesMatch ^(index\.html)?$>
Order allow,deny
Allow from all
</Files>
By making the filename optional (trailing ?
) this effectively matches both passes: an empty filename and index.html
.
Note that if both the URLs /
and /index.html
are available and serve the same content then you should canonicalise the URL in some way to avoid potential duplicate content issues. (Preferably a redirect from /index.html
to /
.)
...and type www.example.com/path
Just to clarify, if the user types www.example.com/path
, where path
is a filesystem directory and a trailing slash is omitted from the URL, then mod_dir will (by default) issue an external 301 redirect to www.example.com/path/
(with a trailing slash) in order to "fix" the URL. So the URL we are dealing with is really www.example.com/path/
.