Disable mod Auto Index

 

If no DirectoryIndex (normally configured as index.html, index.htm, index.php, welcome.html) present in a directory, and if mod_autoindex is enabled (which by default is normally enabled), Apache would list the directory contents, as the following;

apache-directory-listing

While useful for some cases, you would want to disable this feature (perhaps for security reason). There are few ways to do this.

Disable mod_autoindex

The easiest way is probably to disable the autoindex module entirely. This would affect all the sites hosted on the server, which could be both good and bad.

The module is called autoindex, and can be disabled by the a2dismod command, as in the following example.

sudo a2dismod autoindex

Directory’s Options directive

The option could be applied per-directory, via the Directory‘s Option directive as the following.

<Directory /var/www/mysite>
    Options -Indexes
</Directory>
Notice that it’s -Indexes and not +Indexes

This could be set in your Apache‘s configuration file.

.htaccess

The above method would also work by adding a .htaccess file with the following content that you want directory listing to be disabled.

Options -Indexes

– See more at: https://docs.oseems.com/general/application/apache/disable-directory-listing#sthash.LwlHWb8u.dpuf