How to disable directory listing in apache?

First option is to edit the file /etc/apache2/sites-avalible/default (i am using ubuntu), then look for the following lines:

  1.  
  2. <Directory /var/www/>
  3.     Options Indexes FollowSymLinks MultiViews
  4.     AllowOverride None
  5.     Order allow,deny
  6.     allow from all
  7.     # This directive allows us to have apache2’s default start page
  8.     # in /apache2-default/, but still have / go to the right place
  9.     #RedirectMatch ^/$ /apache2-default/
  10. </Directory>
  11.  

And then take out the word Indexes, then your file will look like

  1.  
  2. <Directory /var/www/>
  3.     Options FollowSymLinks MultiViews
  4.     AllowOverride None
  5.     Order allow,deny
  6.     allow from all
  7.     # This directive allows us to have apache2’s default start page
  8.     # in /apache2-default/, but still have / go to the right place
  9.     #RedirectMatch ^/$ /apache2-default/
  10. </Directory>
  11.  

Finally we just reload apache

  1.  
  2. sudo /etc/init.d/apache2 restart
  3.  

If you want to use .htaccess, you have two options:

  1.  

This option will show a forbidden message:

Forbidden

  1.  

empty

One thought on “How to disable directory listing in apache?

Leave a Reply

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