Apache Web Server Prevent Directory / Folder Listing

by Vivek Gite · 11 comments

Q. If there is no index.html or index.php, Apache displays all other files in a Directory. How do I force Apache web server not to display my directory / folder list?

A.This controlled by a module called mod_autoindex or mod_dir.

You can completely remove (or replace) automatic index generation as per your requirements. The IndexIgnore directive adds to the list of files to hide when listing a directory. File is a shell-style wildcard expression or full filename. Multiple IndexIgnore directives add to the list, rather than the replacing the list of ignored files. By default, the list contains . (the current directory). Open your httpd.conf or .htaccess file and append following directive to block auto indexing for all pdf and mp3 files:
IndexIgnore *.pdf *.mp3
To enforce or deny complete folder listing, use *:
IndexIgnore *
Save and close the file. Restart httpd if httpd.conf was updated:
# service httpd restart

Further readings:

=> Apache mod_autoindex help pages.

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 11 comments… read them below or add one }

1 Scott Oertel 12.07.07 at 1:34 pm

also placing “Options -Indexes” in an htaccess file or in a directory directive in the httpd.conf would disable directory browsing/listings

2 S. Fanara 04.22.08 at 2:45 pm

Thank you for this article. I was looking for a “confirmation” about the wildcard character “*” to make sure it could be used with the directive “IndexIgnore” in order to prevent listing of files and folders on all Apache server directories. The apache mod_autoindex help page did not make any mention of it specifically, instead gives a rather generic example were wildcards are used in conjunction to file extension (like in: *.bak)… and although that is a clear hint to more tech savvy people, others may like to have it “spelled out” to be sure they will not run into problems.

At first I thought about using “*.*”, but most likely that wouldn’t have worked on folders… so I thought that it must have been possible to just use “*” to mean “everything” (any folder and any file).

Thanks again for spelling it out ;)

3 Simi 05.09.08 at 7:34 am

I have changed th IndexIgnore * in my httpd file but still am able to see the files in the directory. Is there any other directives needs to get changed to disable the directory browsing.

4 toan 08.30.08 at 4:49 am

I have changed th IndexIgnore * in my httpd file but still am able to see the files in the directory. Is there any other directives needs to get changed to disable the directory browsing.

5 toan 08.30.08 at 4:50 am

I have changed th IndexIgnore * in my httpd file but still am able to see the files in the directory. Is there any other directives needs to get changed to disable the directory browsing.

me too. any I dieal for this?

6 SinhNT 12.09.08 at 9:59 am

Yes. You can modify the config file (httpd.conf) of the Apache server as follows:
1. Options None
2. AllowOverride All
3. Restart the Apache server to take effect.

If you can not access to the Apache’s config file. You should contact to the host’s admin to modify this file so that the line “IndexIgnore *” in your .htaccess file takes effect.

Good luck.

7 Snipervzln 04.24.09 at 9:50 pm

I prefer Scott’s solution; use it on your .htaccess inside the folder you want to hide. It’s better (and customizable) a 505 forbidden page than a empty folder list. Thanks for the post.

8 Vinicius Brasil 05.16.09 at 1:35 am

I want to configure the folder to display the files for download, but want to customize the page that is returned by the webserver. Anyway of doing that without creating a separate page.

9 Balakrishnan 07.23.09 at 7:18 am

How do i enable files and folder listing for a particular folder?

10 selim 09.20.09 at 11:08 am

I prefer Scott’s solution – thanks scotty :)

11 Sebastian 01.15.10 at 9:49 pm

HI

Can anyone tell me how to remove items from the IndexIgnore list? New commands in a subdirectory only add to the list, but I need some files to be displayed which would be hidden some levels above. I didn’t finde anything in the official documentation, but I hope I have only overlooked something…

Is there a way to acchieve this?

Sebastian

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All