Turn On/Off Apache Directory Listing

If a web client requests a URL that points to a directory and the directory does not contain a filename that matches the DirectoryIndex directive, then the apache module mod_autoindex can be configured to present a listing of the directory contents.

Locating the configuration file

The Apache configuration file could be in various places depending on your *nix distribution. For example:

  • /etc/httpd/httpd.conf
  • /etc/apache2/apache2.conf (typically *buntu distributions)
  • /etc/httpd/conf/httpd.conf (typically RH distributions)

One sure way to determine the location of your configuration file is to run the following:

sudo apachectl -V | egrep "(HTTPD_ROOT|SERVER_CONFIG_FILE)"
 -D HTTPD_ROOT="/etc/apache2"
 -D SERVER_CONFIG_FILE="apache2.conf

From the above output, we determine that our configuration file is located as:


Turning ON directory listing

To enable automatic directory indexing/browsing, find the Options directive that applies to the directory and add the +Indexes keyword.

For example:

<Directory /path/to/directory>
    Options +Indexes

Turning OFF directory listing

To turn off automatic directory indexing, remove the Indexes keyword from the appropriate Options line. To turn off directory listing for a particular subdirectory, you can use Options -Indexes.

For example:

<Directory /path/to/directory>
    Options -Indexes