Published January 25, 2018 by

Disable Directory Listing in Apache

If our website document directory does not have an index file, that time the Apache web server will show all the files and folder of the document root directory. Like as below image.

This feature could be turned off for a specific directory through 'options directive' available in the Apache configuration file.

Edit apache virtual host file.

# vim /etc/httpd/conf/httpd.conf                   ## for centos/redhat
# vim /etc/apache2/apache2.conf                  ## for ubuntu/debian

Add following line into virtual host file

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

Restart Apache

# service httpd restart                                           ## for centos/redhat
# systemctl restart apache2                           ## for ubuntu/debian

Now apache shows /index of look like this: