How to Enable or Disable Directory Indexing in cPanel
Introduction
At Lanetti, we understand that controlling how visitors interact with your website is essential for both security and usability. Directory Indexing in cPanel determines whether the contents of a directory are displayed when no index file (like index.html
or index.php
) is found. By enabling or disabling directory indexing, you can manage whether or not users can browse through your website’s folder structure. This guide will help you enable or disable directory indexing in cPanel.\
What Is Directory Indexing?
When directory indexing is enabled, if a visitor navigates to a folder on your website without specifying a specific file (e.g., http://www.yourdomain.com/folder/
), the server will display a list of all files in that folder. If directory indexing is disabled, visitors will either see an error or be redirected to another page if they try to access a directory without an index file.
Why disable directory indexing?
- Security: Disabling directory indexing prevents users from seeing the structure and files within a folder.
- Privacy: Keeps file names and folder contents hidden from the public.
- Improved user experience: Avoids displaying a messy or unorganized list of files to visitors.
How to Enable or Disable Directory Indexing in cPanel
Step 1: Log in to Your cPanel
- Open your browser and navigate to your cPanel login page (e.g.,
https://yourdomain.com/cpanel
). - Enter your username and password, then click Log in.
Step 2: Access the Index Manager
- In the cPanel dashboard, locate the Advanced section.
- Click on Indexes. This will take you to the Index Manager tool.
Step 3: Select the Directory
- In the Index Manager, you’ll see a list of the directories on your website.
- Select the directory for which you want to enable or disable indexing.
- If you want to apply the change to the entire website, select the root directory (usually
public_html
).
- If you want to apply the change to the entire website, select the root directory (usually
Step 4: Enable or Disable Directory Indexing
-
Once you have selected the directory, you will be presented with several options:
- Default System Settings: This option lets the server decide whether indexing is enabled based on your server’s configuration.
- No Indexing: Disables directory indexing for the selected directory, meaning users will see a 403 Forbidden error or be redirected to another page (if configured).
- Standard Indexing: Enables directory indexing, which will show visitors a list of files if no index file is found.
- Fancy Indexing: This option also enables indexing but with a more visually appealing list (file names are displayed with extra features like sorting options and file sizes).
-
Select the appropriate option based on your needs.
- To disable directory indexing, choose No Indexing.
- To enable directory indexing, choose either Standard Indexing or Fancy Indexing.
-
After selecting the desired option, click Save to apply the changes.
How to Disable Directory Indexing for the Entire Website (using .htaccess)
If you want to disable directory indexing for all directories on your site, you can edit the .htaccess
file.
-
In cPanel, navigate to the File Manager under the Files section.
-
Go to the public_html directory.
-
Look for the
.htaccess
file (if it doesn't exist, you can create one). -
Right-click on
.htaccess
and choose Edit. -
Add the following code to disable directory indexing:
Options -Indexes
- Save the file. This will disable directory indexing for all directories under
public_html
.
How to Enable Directory Indexing for the Entire Website (using .htaccess)
If you want to enable directory indexing globally for your website, follow these steps:
-
In the File Manager, open the
.htaccess
file in the public_html directory. -
Add the following code to enable indexing:
Options +Indexes -
Save the file. This will enable directory indexing for all directories under
public_html
.
Important Notes
- Security Considerations: Disabling directory indexing is generally recommended for websites where you don’t want users to see internal files or directory structures.
- Error Handling: If directory indexing is disabled and no index file exists, users will likely see a 403 error or be redirected, depending on the server configuration.