in Apache

How to disable Directory Listing in Apache

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

One of the “must do’s” on setting a secure Apache web server is to disable directory browsing, because the default indexing is enabled in Apache web server. Generally, this happens, when there is no index (default) file is available in the directory (ex: index.html, index.php…).

Then Apache doesn’t understand, which file to display on page and list all files on-page. You can see the below screenshot as there is no index file available. Therefore, directory listing or browsing should be disabled as soon as you finish installing your Apache web.

How to disable Directory Listing in Apache

 

Disable Directory Listing in Apache

To disable the directory listing for a specific directory, add the following settings in Apache Virtual Host or create a .htaccess file in that directory with below content. The Options -Indexes disabled the listing of files on the website if an index file is missing.

In Apache Virtual Host:

<Directory /var/www/public_html>
      Options -Indexes
</Directory>

In .htaccess file:

Options -Indexes

While using the .htaccess, make sure that Apache server is enabled to use .htaccess files for that directory. In most cases, .htaccess is disabled by default.

Finally, reload the Apache service after doing changes in Virtual host to apply changes. The .htaccess changes will apply immediately without reloading service.

Written By:

Blog for everything about hosting, website, server and technical support

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.