How to disable apache directory listing or indexing

disable apache directory listing or subdirectory

To disable apache document root subdirectory or directory listing?

I had an issue before a month ago my all document root subdirectory not secure like that
browser showing my all subdirectory or files.

To secure apache subdirectory or file follow given step:-

There is two way to disable directory listing or subdirectory of the Apache server
1. To edit 
the apache configuration file
2. To edit .htaccess file

To edit the apache configuration file
1. open your server using putty.
2. open apache 
configuration file. you need to do some change in this file
open apache configuration file with this command

# vim /etc/httpd/conf/httpd.conf

    <Directory /var/www/>
         Options Indexes FollowSymLinks
         AllowOverride None
         Require all granted

disable apache directory listing

Edit Options Indexes FollowSysLinks to Options FollowSysLinks    

    <Directory /var/www/>
         Options FollowSymLinks
         AllowOverride None
         Require all granted

Hide apache directory listing
save and close the file. and restart apache server with this command

# sudo service httpd restart

Now check with access subdirectory or file all are secure now.

To edit .htaccess file

If .htaccess file already
otherwise, you need to create a .htaccess file in the document root directory.
exits then need to change step given below.

1. Open the .htaccess file with using this command.

# vim /var/www/html/.htaccess

you need to add the line:-     
    Options -Indexes

htaccess indexoptions

then save and close the file, restart apache server with this command.

# sudo service httpd restart

Congratulations, your apache server disable directory listing or subdirectory.

If you have any query comment below


Blog type: 

Add new comment

Authored By

Sandeep Gurjar

Hy all, This is Sandeep Gurjar am the founder of I am a Redhat Certified Engineer (RHCE) / AWS Solutions Architect-Associate and working as an system administrator since 2016.

Follow us on

Facebook​  Twitter  LinkedIn  Google+