You are currently viewing How to Restrict Directory Listing in cPanel

How to Restrict Directory Listing in cPanel

For anyone managing a website through cPanel, ensuring that your directories are secure and not openly visible on the internet is important. Directory listings can accidentally expose sensitive files to the public, which could lead to security vulnerabilities. Fortunately, cPanel provides easy-to-use features to restrict directory listings, enhancing the privacy and security of your website. This blog post will tell you through the process of restricting directory listings in cPanel, step-by-step.

This blog is a part of our cPanel server management services where we make sure your cPanel server works efficiently with any issues.

What is a Directory Listing?

A directory listing occurs when a web server displays a list of files and folders within a directory because there is no index file (like index.html or index.php) in that directory. This can give visitors insight into the structure of your files, which is often not desirable.

Why Restrict Directory Listings?

Restricting directory listings helps:

  • Protect sensitive information.
  • Prevent unauthorized access to your files.
  • Maintain the professional appearance of your website.

How to Restrict Directory Listing in cPanel

Here’s how you can prevent directory listings using cPanel’s built-in features:

Step 1: Access Your cPanel Account

You can usually access cPanel by typing into your browser’s address bar, replacing with your actual domain name.

Step 2: Locate the Indexes or Index Manager

Once you are logged into cPanel, you need to locate the tool to manage your indexes. This could be named “Indexes” or “Index Manager.” It is typically found under the “Advanced” section of your cPanel dashboard, but this can vary depending on the theme and setup of your cPanel. Click on this icon to open the Indexes configuration.

Step 3: Choose the Directory

After clicking on the Indexes or Index Manager, you will see a list of directories on your account. Navigate through the directories by clicking on the folder icons until you find the directory for which you want to restrict the listing. If you want to apply the settings to the root directory, you will typically choose public_html or www.

Step 4: Edit Indexing Settings

Once you select the directory, you will be presented with a few options regarding how the directory is indexed:

  • Default System Setting: Leaves the settings as configured by your web hosting provider.
  • No Indexing: This option prevents the directory from being listed. This is what you should select to restrict directory listing.
  • Standard Indexing (without fancy styling): Lists the contents of the directory as plain text links.
  • Fancy Indexing: Lists contents with additional formatting and icons.
  • Select No Indexing and click the “Save” button. This action will update the settings and apply the change to the directory you selected.

Step 5: Verify the Changes

To verify that directory listing is restricted, open a web browser and try accessing the directory. If configured correctly, you should see a 403 Forbidden error or be redirected to another page, depending on your server’s setup.

Step 6: Additional Security (Optional)

For added security, you can manually edit the .htaccess file in the directory you want to protect. Simply add the following line to the .htaccess file:

Options -Indexes

This line ensures that directory listing is disabled, overriding other settings unless specifically allowed elsewhere.


Restricting directory listings in cPanel is a straightforward process that significantly enhances the security of your website. By following the steps outlined above, you can ensure that visitors cannot view the contents of directories unless you have explicitly allowed it. Regularly check and manage these settings as part of your routine website maintenance to keep your site secure and professional.


Q1. How do I prevent a directory listing in cPanel?

To prevent a directory listing in cPanel, navigate to the “Indexes” section under the “Advanced” category in your cPanel dashboard. There, you can choose the directory you want to adjust and set its indexing to “No Indexing.” This prevents browsers from displaying a list of the directory contents.

Q2. How do I restrict access to a folder in cPanel?

To restrict access to a folder in cPanel, use the “Directory Privacy” option under the “Files” section. Select the folder you wish to protect, choose to password protect it, and create a username and password for access. This will require anyone trying to access the folder to enter the credentials.

Q3. How do I disallow a directory listing?

To disallow a directory listing, you can add a line of code to the .htaccess file within the directory you want to protect. Simply add Options -Indexes to the file. This command tells the server to disable directory listing for that particular directory.

Q4. How do I remove a listing directory?

Removing a directory listing can be done by editing the .htaccess file in the directory you want to modify. Add the line Options -Indexes to prevent the server from listing the contents of the directory. If the directory does not have a .htaccess file, you can create one and add this line to it.