Prevent Directory Listing using htaccess

When any user comes to the website and if your default page like index.html, index.php not found then webserver will list out all the directories and files to the webpage.

Here is the snippet which disable the directory listing to the web page. Below code will produce 403 error if no default page is found.

Disable Directory Listing

# Disable directory listing Options -Indexes
# Disable directory listing
Options -Indexes

Also we can disable specific files to be listed on the web page. Suppose if you don’t want to list out the .zip and .txt file.
Below code will not list .zip and .txt file and rest of all files will be listed.

Disable only .zip and .txt files Listing

# Prevent listing of zip and txt files IndexIgnore *.zip *.txt
# Prevent listing of zip and txt files
IndexIgnore *.zip *.txt

Note: We can setup the default file access using “DirectoryIndex” directive.

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by: