Websites hosted in cPanel by default are configured to display the index of a directory whenever DirectoryIndex files such as index.html or index.php are not present. This is due to mod_autoindex for Apache being installed and enabled by default.
You can prevent Apache from displaying the directory content by using -Indexes directive or using .htaccess file, or you could disable mod_autoindex entirely.
mod_autoindex Apache module in cPanel can be disabled from the dashboard.
Steps to disable Apache directory listing in cPanel:
- Log in to your cPanel account.
- Go to Advanced section and click on Indexes.
- Select the web directory that you want to disable directory listing on.
Click on the folder icon to browse the directory and click on the folder name to select the particular directory.
public_html is the root of the web folder and selcting it will apply the setting to all the subsequent subfolders. Some hosting also has www which is just a softlink to public_html so effectively they're both the same directory
- Select No indexing from the option and click on the Save button.
What happens in the background is cPanel will append the following line to the folder's .htaccess file to disable directory listing.
New .htaccess file will be created if it doesn't already exist.
- Go back to the directory list and notice the icon on directories with directory listing disabled.
Comment anonymously. Login not required.