How to Turn Off Directory Indexing on WordPress
Directory indexing can be convenient for users browsing your website, since it lets them view the contents of a directory when no index file is present. In most cases, though, you don’t want your site’s directories accessible this way – it can pose real security risks or expose information you’d rather keep private. Turning off directory indexing is a simple but important step in securing your WordPress site and keeping control over what visitors can actually see.
Here’s how to disable directory indexing on your WordPress site, along with the reasoning behind it and a few best practices for keeping things secure afterward.
What is Directory Indexing on WordPress?
Directory indexing is a web server’s ability to display a list of files and folders inside a directory when there’s no default index file (like index.php or index.html) present. It’s convenient for browsing, but it can also expose sensitive files or data to anyone who stumbles onto the URL. Disabling it improves security by keeping your directory structures and contents out of public view – especially important for protecting private or system files on your WordPress site.
How Directory Indexing Works
When someone visits a directory URL without specifying a file (e.g., http://example.com/images/), the web server looks for an index file inside that directory – commonly index.html, index.php, or default.html. If it can’t find one, the server may generate a directory listing instead, showing the folder’s contents in a browsable format.
Also Read: What is WordPress?
Why Turn Off Directory Indexing?
A few reasons this is worth doing:
- Security: Directory indexing can expose sensitive files and folders you’d rather keep hidden – configuration files, backups, or anything else a malicious visitor could exploit.
- Privacy: Turning it off means visitors can’t browse your site’s directory structure and stumble onto files that were never meant to be public.
- Professionalism: A site without directory indexing simply looks more polished – visitors won’t hit a raw file listing if they land on a directory with no index file.
How to Turn Off Directory Indexing on WordPress
There are a few ways to do this. Here are three: editing the .htaccess file, modifying the httpd.conf file (Apache servers), or using a security plugin.
1. Using the .htaccess File
The .htaccess file is a configuration file Apache uses to control various parts of your site. This is the most common way to disable directory indexing on Apache-hosted WordPress sites.
Steps:
- Access Your
.htaccessFile:- Access it via FTP or through your hosting control panel’s file manager.
- It’s typically located in the root directory of your WordPress installation.
- Edit the
.htaccessFile:- Open it in a text editor.
- Add the following line at the end of the file:
Options -Indexes
- Save and Upload:
- Save your changes.
- If you’re using FTP, upload the updated
.htaccessfile back to your server, overwriting the old one if prompted.
- Verify:
- Navigate to a directory without an index file. You should see a 403 Forbidden error or get redirected to a default page, confirming directory indexing is disabled.
2. Modifying the httpd.conf File (For Apache Servers)
If you have access to the Apache configuration file (httpd.conf), you can disable directory indexing directly from there. This one’s better suited to advanced users or server admins.
Steps:
- Access the
httpd.confFile:- Locate and open
httpd.confon your server, usually found in the Apache configuration directory.
- Locate and open
- Find or Add the DirectoryIndex Directive:
- Look for a directory settings block – you’ll likely see something like this:
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
- Remove
Indexesfrom theOptionsline so it looks like this instead:
<Directory "/var/www/html">
Options FollowSymLinks
AllowOverride All
</Directory>
- Save and Restart Apache:
- Save your changes to
httpd.conf. - Restart Apache for the changes to take effect – usually with a command like:
- Save your changes to
sudo service apache2 restart
- Verify:
- Navigate to a directory without an index file and confirm indexing is disabled.
Also Read: How to Create Coupons on WordPress Products
3. Using a Security Plugin
If you’d rather not edit server files directly, several security plugins can handle directory indexing for you.
Steps:
- Install a Security Plugin:
- From your WordPress dashboard, go to Plugins > Add New and search for a security plugin like Wordfence Security, Sucuri Security, or iThemes Security.
- Activate and Configure the Plugin:
- Install and activate your chosen plugin.
- Head into its settings and look for options related to directory listing or indexing – most security plugins include a setting for this.
- Save Settings and Verify:
- Save your changes.
- Navigate to a directory without an index file to confirm indexing has been disabled.
Best Practices
- Regularly Update: Keep WordPress core, themes, and plugins updated to maintain security.
- Monitor Access Logs: Keep an eye on your server’s access logs for anything unusual.
- Backup Regularly: Regular backups mean you can recover quickly if something goes wrong during a configuration change.
Keeping Your Directories Private
Disabling directory indexing is a simple step that goes a long way toward securing your WordPress site and making it look more polished. Whether you edit the .htaccess file, modify server configuration files, or use a security plugin, the goal stays the same – keep your directories out of view for anyone who shouldn’t be poking around in them.
If you run into trouble, your hosting provider or a WordPress professional can help sort it out. Staying proactive about site security pays off in the long run, for both your data and your visitors.
Interesting Reads:

