Directory listing is a default server feature that shows the contents of a directory (folder) when there is no index file such as index.php or index.html in the folder.
When directory listing is enabled, visitors can see a list of all files and subdirectories within that directory and they can also download any file, and that might pose a security risk as it may expose any sensitive files or configuration information.
Disabling directory listing prevents such exposures, it forces the server to show a “403 Forbidden” error if there is no index file.
This can either be done manually by adding a line of code on .htaccess file as shown below:
Step-1 Open your cPanel dashboard.
Step-2 Go to “File Manager” and open the root directory of your website (usually public_html) or any directory where you want to disable directory listing.
Step-3 Look for the .htaccess file in the root directory.
Step-4 If it doesn’t exist, create a new file named .htaccess.
Step-5 Add this line inside the .htaccess file: “Options -Indexes”
Step-6 Save the file and exit.
Directory listing is now disabled for your site.
Alternatively,
Step-1 On cPanel, navigate to the “Advanced” section,
Click the “Indexes” link or icon.
Step-2 Click the folder icon and enter a directory
Step-3 Click the directory name to configure a directory and turn indexing on or off.
Step-4 Select the “No Indexing” option
Step-5 Click the “Save” button.
Another way of doing the same thing is:
Step-1 Navigate to the “File Manager”
Step-2 Right-click the directory and select “Manage Indices”.
Step-3 This automatically takes you to the “Indexes” page (where we were in step 2 of the above method).
Step-4 Click the folder icon and enter a directory
Step-5 Click the directory name to configure a directory and turn indexing on or off.
Step-6 Select the “No Indexing” option
Step-7 Click the “Save” button.
Following any of the above methods is going to disable the directory listing.