How to disable Directory Listing using .htaccess

Directory Listing allows your website visitors to get a complete list of all the files and folders that live on your site. The browser will display all the contents of the directory if you do not create an “index.html” file in that directory.

Protecting your directory by preventing or disabling Directory Listing from your website visitors will increase the security of your website. At least it will make it difficult for people who intend to find security holes on your website.

If you do not protect the directory that you create when someone accesses the directory, it will appear as follows.

directory-listing-01

You can see all the contents of the directory will appear in the browser. To protect it, you can add an empty “ index.html ” file in each directory you create.

Another way is to add the file “ .htaccess ” to the root of your website. You can create the file with Notepad and add the following code to the “.htaccess “.

Options All –Indexes

Internal Server Error message will appear in the browser, as shown in the following image.

directory-listing-02

The next method is still using the “.htaccess ” and you add the following code

IndexIgnore *

The display in the browser will display as if the directory does not contain any files, as shown below.

directory-listing-03

You can choose the method of protection that you think is suitable for your needs and combine it with other methods and techniques to protect your website.

RELATED ARTICLES

Latest Articles