How to prevent Directory Listing using .htaccess

In webhosting, you generally find that files in the directory are listed by default. Sometime it is useful but it can also rise the security issue. You can easily disable or enable this feature using one line in .htaccess file.

Options +Indexes

This enables Directory listing.

Options –Indexes

This disables directory listing for your web site.
The .htaccess file gives more then simply enabling and disabling of a directory listing. With .htaccess file you can control which files to be ignored when creating a directory list.
For example:

IndexIgnore *.doc *.gif *.zip *.txt

Will make the apache server to skip all doc, gif, zip and txt files from the directory list.

IndexIgnore *

Will just create an empty directory list.
Blank index file can also be used for disabling the directory listing, but it is much tedious cause we need to put it in each and every folder. So using .htaccess is much handy for the purpose.

Leave a Reply

Your email address will not be published. Required fields are marked *