Controlling how visitors interact with your website’s directories is important for both security and user experience. In cPanel, directory indexing determines whether visitors can view a list of files in a folder that doesn’t have an index file (like index.html or index.php).
This guide explains how to enable or disable directory indexing in cPanel, either for specific folders or your entire site using .htaccess.
What Is Directory Indexing?
When directory indexing is enabled, and someone visits a URL like:
and no index file is present, the server displays a list of files in that folder.
When directory indexing is disabled, visitors will:
-
See a 403 Forbidden error, or
-
Be redirected elsewhere (if configured).
Why Disable Directory Indexing?
-
Security: Prevents exposure of sensitive or internal files.
-
Privacy: Hides file and folder names from the public.
-
Cleaner experience: Avoids showing raw file lists to visitors.
How to Enable or Disable Directory Indexing in cPanel
1. Log in to Your cPanel
-
Open your web browser and go to your cPanel login page (e.g., https://yourdomain.com/cpanel).
-
Enter your username and password.
-
Click Log in.
2. Access the Index Manager
-
Scroll down to the Advanced section in the cPanel dashboard.
-
Click on Indexes to open the Index Manager tool.
3. Select the Directory
-
In the Index Manager, navigate through your folder structure.
-
Click the folder icon next to the directory you want to configure.
-
To apply changes to your entire site, select the root folder, typically public_html.
-
4. Choose the Indexing Option
- After selecting the directory, choose one of the following options:
-
Default System Setting: Uses the server’s default indexing behavior.
-
No Indexing:
Disables indexing. Visitors will not see the folder contents and will receive a 403 error or redirection. -
Standard Indexing:
Enables plain text listing of files when no index file is present. -
Fancy Indexing:
Enables a styled, readable file list with features like file sizes and sorting. - To disable indexing, select No Indexing.
To enable indexing, choose either Standard Indexing or Fancy Indexing.
-
- Click Save to apply your changes.
How to Disable Directory Indexing for the Entire Website (.htaccess Method)
If you want to prevent directory listing site-wide:
-
In cPanel, go to the File Manager under the Files section.
-
Navigate to the public_html directory.
-
Locate the .htaccess file.
-
If it doesn’t exist, click +File to create one.
-
-
Right-click .htaccess and choose Edit.
-
Add the following line:
-
Save the file.
This disables indexing for all folders under public_html.
How to Enable Directory Indexing for the Entire Website (.htaccess Method)
To enable directory listing site-wide:
-
Open the .htaccess file in the public_html directory via File Manager.
-
Add the following line:
-
Save the file.
This enables indexing for all directories under your website root.
Important Notes
- The .htaccess method works only with a Apache web server. If your hosting uses Nginx or another web server, .htaccess files will not affect directory indexing. In that case, contact your hosting provider for alternative configuration options.
-
Security Tip: It is recommended to disable directory indexing unless you specifically want to expose file listings (e.g., for downloads or open directories).
-
Error Handling: If indexing is disabled and no index file exists, users may receive a 403 Forbidden error or be redirected—depending on your server settings.
-
Customization: You can override indexing settings for individual directories using their own .htaccess files.
- Add an index file instead of disabling indexing: If you don’t want users to see a file listing, you can simply place an index.html or index.php file in the directory. Most servers are configured to display that file automatically and not show the folder contents.