WordPress GuideSecurity → Disable Directory

How to disable directory browsing in WordPress

Apache HTTP Server — What is Apache Web Server Used for? Learn About Apache Server | Liquid Web

If you’ve ever stumbled across a blank directory listing filled with files on a WordPress site, you’ve seen a major security risk in action. That’s directory browsing—also called directory indexing—and it’s one of the easiest ways attackers can peek into your site’s file structure. 

Let’s walk through how to disable it, why it matters, and the different options you have.

What is directory browsing and why is it dangerous?

By default, if a folder on your WordPress server doesn’t have an index file (like index.php or index.html), your web server might display a full list of files in that folder. This is called directory browsing.

That might not sound like a big deal—but it absolutely is. Hackers and bots often scan for open directories because they can:

And it’s not just about security. Search engines may index these directories, cluttering your search results with random file listings and damaging your SEO.

How to check if directory browsing is enabled

Before you disable it, you can test whether it’s currently active. Just type in the URL to a folder on your site that doesn’t have an index file. For example:

https://yoursite.com/wp-includes/

If you see a list of files, you have directory browsing enabled. If you see a blank page or a 403 Forbidden error, it’s already disabled.

Method 1: Disable directory browsing using .htaccess

This is the most reliable and direct method, especially for Apache-based servers (which most WordPress hosts use). You’ll need to edit your site’s .htaccess file.

Step-by-step instructions

Important .htaccess notes

Method 2: Use a plugin to disable directory browsing

If you’re not comfortable editing core files or you want extra security features, plugins are a great alternative.

Recommended plugins

Once installed, these plugins typically include a “Hardening” or “File Permissions” tab where you can enable protection against directory browsing.

Method 3: Block indexing with WordPress settings (not the same, but helpful)

While this doesn’t stop file listing, you can prevent search engines from indexing your whole site or directories.

Go to Settings > Reading in your WordPress dashboard and check the box for “Discourage search engines from indexing this site.” This sends a noindex request in your site’s metadata.

This method won’t stop humans or bots from viewing directory listings—it’s just a polite request to search engines.

Bonus tip: Use server-level tools if you’re not on Apache

If you’re using NGINX instead of Apache, .htaccess changes won’t do anything. You’ll need to update your server config like so:

autoindex off;

This should go inside the location / block of your NGINX config file. If you’re not sure how to do this, contact your host or server admin.

Additional resources

Comprehensive guide to securing WordPress with ModSecurity

This guide provides a comprehensive overview of how to use ModSecurity to enhance the security of your WordPress site.

WordPress vulnerability scanners  →

Learn how a WordPress vulnerability scanner protects your site by detecting and addressing security risks early.

Why security matters for WordPress enterprise hosting

Use the blog as your guide to attacks to watch out for, security best practices, and steps to improve the WordPress protection you already have.

Lindsey Miller is the former Partner Manager for Liquid Web Managed WordPress Hosting. She’s been involved in various aspects in the WordPress community for over 7 years and helped start a non-profit teaching kids to code, The Div.