Htaccess Prevent directory listings or enable folder listing

Using htaccess to prevent directory listings can be helpful in so many ways, if you have key directories with important zips, and archive files or you simply want to prevent others from viewing your image directories.

In order to disable directory listings, simply create .htaccess file and put the following instruction in it, it will block folder listing.

IndexIgnore *

This command line will instruct the server to disable the directory listings and all those files within the directories that contain .htaccess file. The * symbol in the command line will simply prevent the directory from displaying any file .

It is possible to use htaccess to prevent or disable the display of some specific types of files, if you want to disable the display of zip files for instance, simply create the .htaccess file, and use the following code line in it

 IndexIgnore *.zip

Another example, if you want only to hie images of the type JPG, GIF or PNG you can use the same instruction as the following

IndexIgnore *.jpg *.gif *.png

On the other hand, if your server is preventing listing folders by default and you want to enable it you can use the following piece of code

Options +Indexes
Comments
  1. No comments yet!, be the first to post a comment.

Your email will not be published, The required fields marked with '*'

*