Apache Web Server Prevent Directory / Folder Listing
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:
- Apache prevent hot linking or leeching of images using mod_rewrite howto
- How do I enable apache file and directory indexing under Linux or UNIX?
- How do I move spam mail to spam folder?
- Backup CentOS or Redhat Directory Server Database (LDAP)
- Forbidden - You don’t have permission to access this page error and solution
Discussion on This FAQ
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!
Tags: apache web server, autoindex, automatic index, htaccess file, httpd, index generation, IndexIgnore *, IndexIgnore *.pdf *.mp3, indexignore directive, php apache, wildcard expression ~ Last updated on: December 4, 2007



December 7th, 2007 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
April 22nd, 2008 (4 weeks ago) 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
May 9th, 2008 (6 days ago) 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.