Search code examples
.htaccessmod-autoindex

Exclude directory from mod_autoindex.c Options -Indexes


I have the following in my .htaccess:

# "-Indexes" will have Apache block users from browsing folders without a
# default document Usually you should leave this activated, because you
# shouldn't allow everybody to surf through every folder on your server (which
# includes rather private places like CMS system folders).
<IfModule mod_autoindex.c>
  Options -Indexes
</IfModule>

However, I have a directory that does not have an index file (and I prefer to keep it this way), which I need to enable access. How do I exclude this directory from the above code?


Solution

  • Despite the following comment (I got this code from someone else):

    # "-Indexes" will have Apache block users from browsing folders without a
    # default document
    

    ...this code does not block users from accessing files in a directory that does not have an index file. Therefore, I do not need to exclude my directory from the above code.

    As an example, example.com/testdir does not have an index file. But, I'm able to access example.com/testdir/testfile.txt