Apache Options -Indexes for sub directories
Since you tagged the question .htaccess
, you could do something like the following in the root .htaccess
file on Apache 2.4:
# Default - Directory listings disabled (mod_autoindex)
Options -Indexes
# Override - Allow directory listings for the root only
<If "%{REQUEST_URI} == '/'">
Options +Indexes
</If>
Normally sub directories will inherit the same settings you apply to their parent directory in Apache. And, as far as I know, you can't change that and there doesn't exist a way to limit the scope of directives to only a single directory level.
That means that you need to:
- set the option/directive you want on the parent directory
- change/override/negate that option/directive for all (current and new) subdirectories.
Rather than doing that for every subdirectory individually it is easiest to that do that with the DirectoryMatch
directive.
In you main httpd.conf (or an include) set
<Directory "/path/to/example.com/">
# enable directory listings
Options +Indexes
</Directory>
<DirectoryMatch "/path/to/example.com/.*/">
# Disable directory listings for all sub directories of /path/to/example.com/
Options -Indexes
</Directory>
(not tested)