How to disable Directory Browsing on Apache

2020-09-01 By Mark 14354 Views linux apache
7 reviews

Enables default indexing on the Apache webserver using the Options + Indexes or Options indexes directory. This usually happens when the index (default) file is not available in the directory. Apache does not understand which file should be displayed on the page and which should list all the files on the page. See the below screenshot as there is no index file available.

directoryapache1


See the instructions for disabling Directory Browsing on Apache.


  1. First you need to activate the .htaccess file for your website in the master apache configuration file. Run the below command to edit the configuration file and then look for the section that is shown in the below image, change the value of the AllowOverride None directive to AllowOverride All, then save and exit.

    # vi /etc/httpd/conf/httpd.conf
    

    directoryapache2

  2. To disable directory listing for a specific directory, create a .htaccess file in that directory with the content below.

    Options -Indexes
    

    directoryapache3

  3. Restart the Apache server with the below commands.

    On SystemD based systems

    # systemctl restart apache2
    
    # systemctl restart httpd
    

    On SysVInit based systems

    # /etc/init.d/apache2 restart
    
    # /etc/init.d/httpd restart
    

    directoryapache4

  4. Now reload the website and the page will show as the below image.

    directoryapache5


Related Tutorials

What do you think about this article?

Rate this article
LayerStack Promotion
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.