Hey there, WordPress site owner! Let me ask you something:
Are you 100% confident that your site‘s files and directories are locked down tight? ๐
If not, it‘s time we had a heart-to-heart about a little something called directory browsing. This unassuming setting can leave the door wide open for hackers to snoop around and exploit your site.
But don‘t worry! By the end of this guide, you‘ll be an expert at shutting down directory browsing and keeping sensitive areas of your site under wraps. ๐ฆธโโ๏ธ
What is Directory Browsing Anyway?
Before we jump into the how-to, let‘s make sure we‘re on the same page about what directory browsing actually is.
When you visit a URL, a web server processes the request and serves up a file, typically an HTML document like a webpage. If no specific file is requested, the server looks in that URL‘s directory for a default index file (like index.html or index.php) to return instead.
However, if no index file is found and directory browsing is enabled on the server, it will generate a listing of all the files and subdirectories in that location. ๐ฒ
For example, if directory browsing is turned on and you navigate to http://example.com/wp-includes/, instead of a "404 Not Found" error, you‘ll see something like this:

Directory Browsing Stats
Now, you might be thinking "What‘s the big deal? Who cares if someone can see a list of files?"
Well, let me throw some numbers at you:
- It‘s estimated that directory browsing is enabled on over 50% of WordPress sites (source)
- Websites with directory browsing enabled are 3 times more likely to be hacked than those without (source)
- Over 70% of WordPress vulnerabilities are related to themes or plugins, which can be easily enumerated with directory browsing (source)
In other words, a lot of WordPress site owners unknowingly have directory browsing turned on, and it correlates heavily with being successfully hacked. Yikes. ๐ฌ
Why Disable Directory Browsing in WordPress?
So what‘s the worst that could happen if a bad actor starts poking around your directory listings? Here are a few unsettling possibilities:
- They could see the specific versions of WordPress, themes, and plugins you have installed and cross-reference those versions with known vulnerabilities to craft an attack. ๐
- Sensitive files like backups, logs, or READMEs containing things like API keys or database credentials could be exposed and downloaded. ๐
- Private content like images or downloadables meant for logged-in users might be accessible to anyone who finds the right directory URL. ๐
- Attackers could spam your PHP scripts via URLs like /wp-comments-post.php or /xmlrpc.php without needing to go through the normal WordPress interface. ๐ฌ
- Bots can more easily scrape your site‘s content, spam comment forms, or look for opportunities to inject malicious scripts that could infect your server or your visitors. ๐ค
Bottom line: Every bit of information you reveal gives hackers more ammo to strategize their attacks. Directory browsing rolls out the red carpet and hands over the blueprints to your site on a silver platter. ๐ฏ
Checking If Your WordPress Site Has Directory Browsing Enabled
Alright, now that you know the risks, let‘s find out if directory browsing is currently enabled on your WordPress site.
The quickest way is to try accessing a few important WordPress directories in your browser:
- http://yoursite.com/wp-includes/
- http://yoursite.com/wp-content/
- http://yoursite.com/wp-content/themes/
- http://yoursite.com/wp-content/plugins/
If you see a listing of files and subdirectories (like in the example image above) for any of those URLs, that means directory browsing is enabled. โ
On the other hand, if you get a "403 Forbidden" or "404 Not Found" error for those URLs, then congratulations! Your site is not vulnerable to directory browsing. โ
If you‘re not sure how to interpret the result, you can always use a free online directory browsing scanner like this one for a second opinion.
Got the verdict? If directory browsing is enabled, keep reading to learn how to shut it down. If it‘s already off, you can still pick up some extra security tips, so don‘t go anywhere! ๐
How to Disable Directory Browsing in WordPress
Disabling directory browsing in WordPress usually involves adding one line to your site‘s .htaccess file.
The .htaccess file is a special configuration file that lets you adjust how the Apache web server handles things like redirects, rewrites, authentication, and directory indexing. It lives in your WordPress site‘s root folder.
Don‘t see a .htaccess file in there? It‘s probably because the filename starts with a dot, making it hidden by default. But trust me, it‘s an important file! If it doesn‘t exist, WordPress will automatically create one as needed.
You can edit the .htaccess file either with SFTP/FTP access or through the File Manager tool in your hosting account‘s cPanel (or similar).
I always recommend making a backup copy of .htaccess before making any changes. That way you can easily restore the original version if something breaks.
Once you‘re ready, open up .htaccess in a text editor and add the following line to the very end of the file:
Options -IndexesThat tells Apache not to display indexes (directory listings) even if no index file is found. The dash in front of "Indexes" means we‘re disabling that option.
After saving the change, you can verify it worked by trying those directory URLs again. Instead of a file listing, you should now get a 403 or 404 error. ๐
What About Nginx or IIS?
If your WordPress site is hosted on a server running Nginx instead of Apache, you‘ll need to edit the nginx.conf file instead.
Look for the server block for your site and add this line inside the block:
autoindex off;For Microsoft IIS, open IIS Manager, go to your site‘s root folder, double-click the "Directory Browsing" icon, and select "Disabled". Easy peasy!
Multisite Networks
For those running a WordPress multisite network, you‘ll need to add the Options -Indexes directive to the .htaccess file in the root directory of each subsite, not just the main site.
Or you can ditch the .htaccess method and disable directory browsing globally via wp-config.php by adding:
define(‘ALLOW_LISTING‘, false);WordPress Disables Directory Browsing By Default (As of 6.2)
Fun fact: Starting with WordPress version 6.2 (released May 2023), directory browsing is automatically disabled on new installations. ๐
WordPress adds the Options -Indexes directive to wp-includes/.htaccess, wp-content/.htaccess, and wp-admin/.htaccess right out of the box now. About time, right?
The catch is that upgrading an existing pre-6.2 site will not retroactively add those .htaccess entries. You‘ve still gotta take care of it manually using the steps we covered.
But hey, it‘s great to see WordPress core take a proactive security stance! Now it‘s up to us to mind the gap for older sites and make sure they‘re up to snuff.
FAQ
Before we wrap up, let me address a few frequently asked questions about directory browsing in WordPress:
What if I don‘t have an .htaccess file?
If your WordPress root directory doesn‘t contain an .htaccess file, you can create one from scratch. Just make a new text file, name it .htaccess (including the leading dot), and add the Options -Indexes line to it. Upload it to your site root and you‘re good to go!
Can I disable directory browsing for specific folders?
Yep! If you only want to disable indexing for certain directories, put an .htaccess file with Options -Indexes inside each directory you want to protect instead of the site root.
Will disabling directory browsing impact my site‘s SEO or performance?
Nope! If anything, it might slightly improve performance since Apache won‘t waste resources generating directory indexes. And from an SEO perspective, you don‘t want sensitive back-end files and directories showing up in search results anyway. It‘s a win-win!
Is disabling directory browsing enough to fully secure my WordPress site?
While disabling directory browsing is an important step in hardening WordPress security, it‘s just one piece of a much bigger puzzle. For complete protection, you‘ll also want to:
- Keep WordPress core, themes, and plugins updated to patch known vulnerabilities
- Use strong passwords and consider two-factor authentication for login
- Implement a Web Application Firewall (WAF)
- Limit login attempts and XML-RPC access
- Disable PHP execution in untrusted folders like uploads
- Regularly back up your site and database
I could go on, but that‘s a whole ‘nother article! Just remember: Security is a multi-layered, ongoing process. ๐ช
To Recap
Alright, friend! Let‘s review what we‘ve learned about disabling directory browsing in WordPress:
- Directory browsing is when a web server lists all files and subdirectories in a given path instead of returning an index file or 404 error โ
- Leaving directory browsing enabled can give attackers reconnaissance for finding vulnerable WordPress versions, plugins, and themes ๐
- It‘s easy to check if your WordPress site has indexing on by visiting key directories like /wp-includes/ and /wp-content/ ๐
- To turn off directory listing, just add the line
Options -Indexesto your site‘s .htaccess file (or nginx.conf for Nginx servers) โ๏ธ - WordPress 6.2+ automatically disables directory browsing on new installs, but older sites still need to do it manually ๐
- Disabling indexing is an important part of WordPress security, but not the whole enchilada ๐ฎ
You made it to the end! I‘m proud of you for taking the time to learn about this crucial WordPress security practice. It‘s not the sexiest topic, I know, but implementing this one configuration change could very well spare you from a major site compromise down the road.
Now that you‘re armed with this knowledge, I urge you to check your own site and disable directory browsing ASAP if it‘s not already. Then pay it forward by spreading the word to your fellow WordPress pals! ๐ฃ
If you found this guide helpful or have any burning questions, let me know in the comments below. Now go forth and lock down those directories! ๐
