How to Disable Directory Browsing in WordPress using .htaccess

If you are still not able to figure out, what did I meant stating disable directory browsing in WordPress?

Then, let me make it clear that, if the owner of the website doesn’t disable directory browsing, then any of the visitors can access their root files saved in their hosting directory.

By default, WordPress shows all the content of the root directory like plugins, themes, Media and other files which don’t contain index.php file in it.

How can the hackers access the WP root files?

All they have to do is typing www.yourdomainname.com/wp-content/uploads in the browser

check out the below example, how the whole directory of content pops up with a simple URL along with the parent directory.


Content of Directory


Sounds scary, isn’t it?

Yes, certainly it would be. When it comes to securing the WordPress website, this is quite underestimated one. Though, quite important. You can’t open the doors and make your site vulnerable to the attacks.

We will see in this article how to disable directory browsing in WordPress for better security.

Disable Directory Browsing in WordPress

The trick is quite simple, we just need to head over to your WordPress Root directory to access the .htaccess file.

Step 1. Login to your Control Panel – File Manager

File Manager

Step 2. Click on public_html, and find .htaccess file in the WordPress root directory.


Step 3. Right Click on it, and Click on Edit.

This will open the file in the text editor. There at the bottom add below given one-line code.

# Disable directory browsing
Options All – Indexes

Step 4. Hit the Save Changes button.

That’s it, you are done and disabled the directory browsing in WordPress and blocked access to your core WordPress files.

To test it you can reload the same page, not it might show an error page or some other page preferred by you.

Further Recommended Reads for better security


10 thoughts on “How to Disable Directory Browsing in WordPress using .htaccess”

  1. Hi Navin,

    Very useful article. That is really a big loophole in wordpress and can be the starting point of trouble. It is astonishing how anyone can access so easily the root contents.

    Thankfully, the solution is quite simple as you have given it here. With just two lines of code we can disable directory browsing and close the loophole.

    Thanks for sharing the valuable information with us. Have a great day!

    • Hi Naveen, welcome to QuestionCage!

      You are absolutely right there. And yes, certainly every coin have another side, so do WordPress loopholes as well instead of being a largest used CMS all around. But, solutions are always there for any kind of WordPress security and errors… Thankfully
      Have a great day ahead!

  2. Hello Navin,

    I actually haven’t think about this. This is really a big security loophole for your blog if your directory browsing is enabled. Hackers can easily sneak into your site. I have just disabled it from the .htaccess file. Thanks for sharing this great tips, bro 🙂

    Have a great day 🙂

  3. Hello Naveen,

    Your article is really nice written and well explained. it’s showing you have best knowledge of wp. can you please explain best way to optimize a wp site. my site takes long time to load.

    thanks i will wait for your response.

    Divya Sehgal


Leave a Comment

QuestionCage Logo Main

Better Security for your WordPress Blog

Get rid of all the Malware injections and stay away from vulnerabilities. Spend a few minutes and sleep tight. Enter your email and get acess to the article.

You have Successfully Subscribed!