Exclude directory from mod_autoindex.c Options -Indexes

1.1k Views Asked by At

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?

2

There are 2 best solutions below

0
Curt On BEST ANSWER

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

0
sa289 On

Create an .htaccess file in that directory, and in it put the following

<IfModule mod_autoindex.c>
  Options +Indexes
</IfModule>