My Web Hosting Manual


Home > .htaccess > How To Prevent Or Allow Directory Listings

How To Prevent Or Allow Directory Listings

A very useful configuration is to prevent a directory listing where anyone can see anything you have in there. Its not nice and you really shouldn't go showing it anyway.
You may have pictures, movies, zips etc that are no ones business but yours. So lets keep them private.
At the same time, in some cases it may be useful to show all files in the directory.

To prevent directory listings, open your .htaccess file and simply add the following line to it:

IndexIgnore *

The above line tells the Web Server to hide or prevent directory listings of directories and files. The "*" is a wildcard meaning do not display any files.
At the same time it's possible to prevent listings of only certain file types, for example you can show listings of ".html" files but not ".zip" files.

To prevent listing '.zip' files, here is the sample code:

IndexIgnore *.zip

The above line tells the Web Server to list all files except those that end with ".zip".

To prevent listing multiple file types, and include the following line:

IndexIgnore *.zip *.jpg *.gif

The above line tells the Web Server to list all files except those that end with ".zip", ".jpg" or ".gif".

On the other hand, if your server does not allow it and you do want to show it, you can add the following code:

Options +Indexes

The above line tells the Web Server to enable directory listing.
You can also reverse this to disable directory listings by replacing the plus sign before the text "Indexes" with a minus sign (Options -Indexes).

If you do show the directory content, only certain files or all of, you can make look nicer by including two files. Include a "HEADER" file which will dress up the top of the page. Anso you may include a "README" file which will dress up the footer area. Directory stuff will be shown in the sapce in between these two files.

Review It

You might also be interested in:






Top Hosting
  - Host Gator
  - Host Monster
  - Blue Host
  - Easy CGI
  - Lunar Pages
       
All content has been created by Juan Carlos Gorospe. These are my opinions and experiences.
Copyright © 2008, Juan Carlos Gorospe. All Rights Reserved.