Prevent Access And Directory Listing To A Folder Using .htaccess

If someone browses to a folder on your website that does not have an index file it will, by default, list the directory’s contents. If you have an Apache based web server you can prevent access to this folder by placing a .htaccess file within it containing the following code:

Options -Indexes

This can also be placed at the root of your site as it will be inherited through the sub-directories. Using Options -Indexes does not prevent access to the folders from scripts running on your website so you can still, for example, list the contents with PHP and download the files.