7 Steps to Prevent directory listing using .htaccess


How to prevent directory listing using .htaccess file?

This tutorial is about preventing your files from showing to the public on your web directory.
Here are the easy steps you can follow to restrict directory listing using .htaccess:

Step 1: Login to Cpanel.

Step 2: Click on the File Manager.


File Manager Option in HostingSewa Cpanel.

Step 3:  Enter the public_html directory


File Manager showing public_html directory

Step 4: Click on the Settings button on the top right corner of File Manager. The button looks like this:file-manager-settings-button

Step 5:  After clicking the Settings button, tick mark on ‘Show Hidden Files (dotfiles)‘. Now, your dot hidden files will be shown including .htaccess (if any).

Show Hidden Files (dotfiles)

File Manager Setting Preferences showing Show Hidden Files (dotfiles) and other options.

Step 6: Right-click on the .htaccess file and click on edit. If .htaccess file is missing you can create a new file name as ‘.htaccess’.


Right-click menu on Cpanel File Manager

Step 7: Now you add the following snapshot on the top of your HTACCESS file.

Options -Indexes


Modifying .htaccess file and saving changes from Cpanel.

This is how directory listing is prevented using the .htaccess file.