How do I disable directory browsing?

0 votes
asked Mar 27, 2010 by arthurprs

I want to disable directory browsing of /galerias folder and all subdirectories

Index of /galerias/409

* Parent Directory
* i1269372986681.jpg
* i1269372986682.jpg
* i1269372988680.jpg

11 Answers

0 votes
answered Mar 27, 2010 by stimpie

Create a .htaccess file with the following:

Options -Indexes
0 votes
answered Jan 17, 2014 by gaurav-kachhadiya

Try this in .htaccess:

IndexIgnore *.jpg
0 votes
answered Mar 4, 2014 by sarvar-nishonboyev

One of the important thing is on setting a secure apache web server is to disable directory browsing. By default apache comes with this feature enabled but it is always a good idea to get it disabled unless you really need it. Open httpd.conf file in apache folder and find the line that looks as follows:

Options Includes Indexes FollowSymLinks MultiViews

then remove word Indexes and save the file. Restart apache. That's it

0 votes
answered Mar 5, 2015 by packetie

This is not an answer, just my experience:

On my Ubuntu 12.04 apache2, didn't find Indexes in either apache2.conf or httpd.conf, luckily I found it in sites-available/default. After removing it, now it doesn't see directory listing. May have to do it for sites-available/default-ssl.

0 votes
answered Mar 16, 2015 by dung

The best way to do this is disable it with webserver apache2. In my Ubuntu 14.X - open /etc/apache2/apache2.conf change from

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

to

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

then restart apache by:

sudo service apache2 restart

This will disable directory listing from all folder that apache2 serves.

0 votes
answered Mar 7, 2016 by justyy

Apart from the aformentioned two methods (edit /etc/apache2/apache2.conf or add Options -Indexes in .htaccess file), here is another one

a2dismod autoindex

Restart the apache2 server afterwards

sudo service apache2 restart
0 votes
answered Mar 7, 2016 by starkeen

To complete @GauravKachhadiya's answer :

IndexIgnore *.jpg

means "hide only .jpg extension files from indexing.

IndexIgnore directive uses wildcard expression to match against directories and files.

  • a star character , it matches any charactes in a string ,eg : foo or foo.extension, in the following example, we are going to turn off the directory listing, no files or dirs will appear in the index :

    IndexIgnore *

Or if you want to hide spacific files , in the directory listing, then we can use

IndexIgnore *.php

*.php => matches a string that starts with any char and ends with .php

The example above hides all files that end with .php

0 votes
answered Mar 29, 2016 by martin-j-h

You can place an empty file called index.html into each directory that you don't want listed. This has several advantages:

  • It (usually) requires zero configuration on the server.
  • It will keep working, even if the server administrator decides to use "AllowOverride None" in the the server configuration. (If you use .htaccess files, this can lead to lots of "Error 500 - internal server error" messages for your users!).
  • It also allows you to move your files from one server to the next, again without having to mess with the apache configuration.

Theoretically, the autoindexing might be triggered by a different file (this is controlled by the DirectoryIndex option), but I have yet to encounter this in the real world.

0 votes
answered Sep 15, 2017 by zish

Open Your .htaccess file and enter the following code in

Options -Indexes

Make sure you hit the ENTER key (or RETURN key if you use a Mac) after entering the "Options -Indexes" words so that the file ends with a blank line.

0 votes
answered Sep 15, 2017 by ziad-eson

Try this within your code:

IndexIgnore *
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...