If you’re running a website on cPanel shared hosting or any server powered by Apache, there’s a chance your visitors can view your directory structure if there’s no index.html or index.php file present. This is called directory listing, and it’s a serious security risk because hackers can see and download sensitive files.
Fortunately, you can disable directory listing easily using a single line in your .htaccess file:
Options -Indexes
This simple trick locks down your folders and keeps your site secure.
What Is Directory Listing?
When directory listing is enabled, visiting a URL like example.com/uploads/ without an index file shows all files in that folder. Here’s an example:
Index of /uploads
-----------------
backup.zip
config.php
database.sql
This exposes sensitive files and makes your site a target for attacks.
Why Disable Directory Listing?
- Improves Security: Hides configuration files, backups, and other sensitive data.
- Prevents Hacking: Hackers often scan for exposed directories to exploit.
- Looks Professional: Instead of a raw directory view, visitors see a 403 Forbidden page.
How to Disable Directory Listing in cPanel
Follow these steps to secure your site:
- Log in to cPanel 
 Access your hosting account and open the File Manager.
- Locate or Create the - .htaccessFile
- Check your website’s root directory (public_html/).
- If there’s no .htaccessfile, click + File and name it.htaccess.
- 
Edit the .htaccessFile Add this line:
   Options -Indexes
- Save Your Changes 
 Once saved, your server will block directory browsing.
- Test Your Site 
 Visit a directory without an index file. You should now see:
 
   403 Forbidden
  
  
  Complete .htaccess Example
Here’s a more robust .htaccess configuration:
# Disable directory listing
Options -Indexes
# Force HTTPS for security
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# Custom error page
ErrorDocument 403 /403.html
Alternative: Disable Directory Listing in cPanel GUI
If you prefer not to edit .htaccess, cPanel also has a Directory Privacy or Indexes option:
- Go to Advanced → Indexes in cPanel.
- Select the folder you want to secure.
- Choose No Indexing.
Key Takeaways
- Adding Options -Indexesto.htaccessis a quick and effective security measure.
- It prevents anyone from seeing your site’s folder structure.
- This method works best for Apache-based servers (common in shared hosting).
 

 
    
Top comments (0)