Are you worried about visitors snooping through your website’s files in directories without an index file? Leaving directory browsing enabled can expose sensitive information or clutter your visitors’ experience. Fortunately, disabling directory browsing is simple and ensures your website stays secure and professional.
In this guide, we’ll show you how to disable directory browsing using your .htaccess
file and walk you through an alternative process using your hosting control panel’s settings. Let’s dive in!
What Is Directory Browsing?
Directory browsing occurs when visitors access a folder on your website that lacks an index
file (like index.html
or index.php
). Instead of seeing a proper webpage, they’re presented with a raw list of files and folders.
For example, visiting https://yourdomain.com/images/
might show every image file stored in that directory if directory browsing is enabled. This can be risky, especially if there are private files, sensitive information, or files that reveal your website’s structure.
Why Should You Disable Directory Browsing?
Disabling directory browsing has multiple benefits:
- Improved Security: Prevents unauthorized users from exploring your website’s structure or downloading sensitive files.
- Professional Appearance: Visitors won’t see unpolished, auto-generated file lists.
- Enhanced Privacy: Protects data you may not want public, like backup files, logs, or configuration files.
How to Disable Directory Browsing Using .htaccess
The .htaccess
file is a powerful tool used to configure your website on an Apache server. To disable directory browsing, follow these steps:
- Access Your Website’s Root Directory
Log in to your hosting account’s File Manager or connect via FTP. Navigate to the root directory of your website. This is typically the folder where your main website files are stored (e.g., public_html
). - Locate or Create the
.htaccess
File- If you see a file named
.htaccess
, open it for editing. - If it doesn’t exist, create a new file and name it
.htaccess
.
- Add the Following Code
Paste this single line into your .htaccess
file:
Options -Indexes
- Save the File
Once you’ve added the code, save and close the file. - Test Your Website
Visit a directory without any index
file (e.g., https://yourdomain.com/images/
). Instead of seeing the list of files, you should now see a “403 Forbidden” error or a blank page.
How to Disable Directory Browsing in cPanel
If you are using cPanel interface, here’s an alternative way to disable directory browsing:
- Log in to cPanel
Use your cPanel credentials to log in to your hosting account’s cPanel. - Navigate to Indexes
- In the Advanced section of cPanel, click on Indexes.
- This tool allows you to control how directories on your website are displayed.
- Select the Directory to Edit
- A list of your website’s folders will appear.
- Click on the folder you want to protect (e.g.,
public_html
to protect the entire site).
- Disable Directory Browsing
- Choose the No Indexing option.
- Click Save to apply the changes.
- Confirm the Change
Visit the folder in a browser to ensure directory browsing is disabled. You should see a “403 Forbidden” error or a blank page instead of a file list.
Final Thoughts
Disabling directory browsing is a quick yet crucial step to enhance your website’s security and maintain a professional appearance. Whether you use the .htaccess
method or cPanel’s Indexes tool, you’ll protect your site from prying eyes and create a safer environment for your visitors.
At Hostingest, we’re dedicated to making website management as easy as possible. With our secure hosting solutions, free SSL, and user-friendly cPanel, your website is always in good hands.
Start your hosting journey today with Hostingest and take control of your website’s security!
Note: By default, directory listing is disabled in Hostingest all hosting plans, so you don’t have to worry about it unless you’ve manually enabled it.