Disable directory listing/browsing – Apache

Often, you don’t want your website users to browse the whole content of a public folder. They will still be able to download files from it but not to list all of them for no reason.

This can be achieved in different ways. Here we cover modifying the Apache configuration file directly.

Open your Apache configuration file for the website you want to amend. Where it is depends on your distribution. In Ubuntu Lucid it’s in /etc/apache/sites-enabled/website_name. Open the file as administrator and look for something like:

<Directory /home/andrea/www/project_name/trunk/public/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

and remove the “Indexes” option so it looks like:

<Directory /home/andrea/www/project_name/trunk/public/>
    Options FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

Now restart Apache to apply the change:

sudo /etc/init.d/apache2 restart

If you prefer not to edit the main configuration file, you can achieve the same result by placing an .htaccess file in the directory with the single line “Options -Indexes”. This is useful on shared hosting where you don’t have access to the server configuration.

Enjoy!

One thought on “Disable directory listing/browsing – Apache”

Leave a Reply

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