Apache .htaccess Guide, Tutorials and Articles
Username:
Password:
Register / My Account / Forgotten Password?

Disable directory listings

(Edit this article)
Preventing directory listings can be very useful if for example, you have a directory containing important '.zip' archive files or to prevent viewing of your image directories. Alternatively it can also be useful to enable directory listings if they are not available on your server, for example if you wish to display directory listings of your important '.zip' files.

To prevent directory listings, create a .htaccess file following the main instructions and guidance which includes the following text:

IndexIgnore *

The above lines tell the Apache Web Server to prevent directory listings of directories and files within the directory containing the .htaccess file. The '*' represents a wildcard, this means it will not display any files. It is possible to prevent listings of only certain file types, so for example you can show listings of '.html' files but not your '.zip' files.

To prevent listing '.zip' files, create a .htaccess file following the main instructions and guidance which includes the following text:

IndexIgnore *.zip

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

To prevent listing multiple file types, create a .htaccess file following the main instructions and guidance which includes the following text:

IndexIgnore *.zip *.jpg *.gif

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

Alternatively, if your server does not allow directory listings and you would like to enable them, create a .htaccess file following the main instructions and guidance which includes the following text:

Options +Indexes

The above line tells the Apache Web Server to enable directory listing within the directory containing this .htaccess file. You can also reverse this to disable directory listings by replacing the plus sign before the text 'Indexes' with a minus sign. e.g. 'Options -Indexes'.

You can also include a default description for the directory listings that is displayed at the top of the page by placing a file called 'HEADER' in the same directory. The contents of this file are displayed before the list of directory contents. You can also include a footer, by creating a file called 'README'. The contents of this file are displayed after the list of directory contents.

<- Enable CGI outside of the cgi-bin Setting server timezone ->

Visitor Comments and Responses

Average Rating: 9.89 out of 10 (37 Votes)

Submit Comment/Rating

Article Rating:
Name: (optional)
Your Comment/Response: (optional)
Powered by OpenCrypt Article Manager
Table of Contents RSS Feed
1. What is .htaccess?
2. How to use .htaccess
3. Error documents
4. Redirects
5. Password protection
6. Deny visitors by IP address
7. Deny visitors by referrer
8. Hot link prevention techniques
9. Blocking offline browsers and 'bad bots'
10. DirectoryIndex uses
11. Adding MIME types
12. Enable SSI with .htaccess
13. Enable CGI outside of the cgi-bin
14. Disable directory listings
15. Setting server timezone
16. Changing server signature
17. Preventing access to your PHP includes files
18. Prevent access to php.ini
19. Forcing scripts to display as source code
20. Ensuring media files are downloaded instead of played
21. Setting up Associations for Encoded Files
22. Preventing requests with invalid characters
23. Useful Resources
 
Sponsors
Space Holder
Space Holder


Copyright © 1999 - 2008 ionix Limited. All Rights Reserved. Company Information, Affiliates

Powered by OpenCrypt Membership Software