About Linux FAQ

Browse More FAQs:

Apache Web Server Prevent Directory / Folder Listing

Posted by Vivek on Tuesday December 4, 07 @5:43 pm

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.

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Linux / UNIX FAQ:

Discussion on This FAQ

  1. Scott Oertel Says:

    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 Says:

    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 Says:

    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.

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Please do not use the comment form to ask for help / question. Ask your question on the excellent Linux tech support forum. Thank you very much for stopping by our site!

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

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , , , ~ Last updated on: December 4, 2007

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.