Preventing directory listing using .htaccess
A simple way to prevent directory listing is using .htaccess file in the target directory.
Imagine that you have a config folder in your site (www.mysite.com/config/) and you want to protect that folder by blocking users from listing the directory contents. To do this:
- Open notepad or any other text editor of your choice.
- Insert the following content:
-
-
Options -Indexes
-
<files .htaccess>
-
deny from all
-
</files>
-
-
- Save the file as “.htaccess” inside the target folder (”www.mysite.com/config/”).
Now, you should see a 403 message if you type “www.mysite.com/config/” in your browser.
If you want to learn more about the .htaccess file and all the things you can do with it, you may be interested in reading Comprehensive Guide to .htaccess.
That’s it!






