Beginner's Guide for WordPress / Start your WordPress Blog in minutes

How to Disable Directory Browsing in WordPress

By default when your web server does not find an index file (i.e. a file like index.php or index.html), it automatically displays an index page showing the contents of the directory. This could make your site vulnerable to hack attacks by revealing important information needed to exploit a vulnerability in a WordPress plugin, theme, or your server in general. In this article, we will show you how to disable directory browsing in WordPress.

An example of directory index browsing in WordPress

Why You Need to Disable Directory Browsing in WordPress

Directory browsing can be used by hackers to find out if you have any files with known vulnerabilities, so they can take advantage of these files to gain access. For the comprehensive security of our sites, we use Sucuri for WordPress security. They have a simple dashboard which allows us to do this and perform many other WordPress security strengthening steps with in few clicks.

Directory browsing can also be used by other people to look into your files, copy images, find out your directory structure, and other information. This is why it is highly recommended that you turn off directory indexing and browsing.

Video Tutorial

Subscribe to WPBeginner

If you don’t like the video or need more instructions, then continue reading.

To disable directory browsing in WordPress all you need to do is add a single line of code in your WordPress site’s .htaccess file located in the root directory of your website. To edit the .htaccess file you need to connect to your website using an FTP client.

Once connected to your website, you will find a .htaccess file in your site’s root directory. .htaccess is a hidden file, and if you can not find it on your server, you need to make sure that you have enabled your FTP client to show hidden files.

You can edit your .htaccess file by downloading it to your desktop and opening it in a text editor like Notepad. Now at the end of your WordPress generated code in the .htaccess file simply add this line at the bottom:

Options -Indexes

Now save your .htaccess file and upload it back to your server using your FTP client. That’s all you need to do. Directory browsing is now disabled on your WordPress site and people trying to locate a directory index on your website will be redirected to WordPress 404 page.

We hope this article helped you learn how to disable directory browsing in WordPress to make your website more secure. For questions and feedback you can leave a comment below or join us on Twitter.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit – a collection of WordPress related products and resources that every professional should have!

Reader Interactions

83 CommentsLeave a Reply

  1. I am in love with this website. Every day I am surprised when I read a new article from this website. Thankfully I read this article today and immediately I implemented the advice.

  2. So is it ok to have this code on .htaccess file even when an index.php file is present in the root folder.

    Kindly respond.

  3. Do you need Filezila to do this or can you go to the FTP via Cpanel and do this?
    Thank you

    • You can use either, not all hosts have a file manager is why we show Filezilla :)

      Admin

  4. Hello
    does this action affect pages indexing on search engines?
    and does it make some problems for indexed pages of my WordPress website?
    Thanks

  5. Amazing post,

    Just have simple question, I added this code and it’s working, the question is Google indexes those page e.g sitecom/wp-contents/2019/2, will Google remove those pages automatically now as these are 404. Or I should remove it in Search Console?

    Thanks

  6. Hello!

    I recently applied this rule
    and at the same day the front page of my blog
    got vanished from google index.

    Do you see any connection?

    • Adding this to your htaccess should not affect your indexing, there are multiple reasons and you would want to check your Google Search Console for what it says about your home page.

      Admin

  7. Thanks for all the tips that you provide!
    I am still wondering how can you hide the wp-content & wp-include folder from sources? I hate it when someone goes right click and source it can see all of my plugins :). Do you have any script for this?
    Thank you in advance!

    • We do not have a recommended method for that at the moment, the most common reason you can’t see those folders in dev tools is a site’s cache.

      Admin

  8. Could you please tell me How can i disable WordPress in sub folder like my WordPress install on [www.mydomain.com] and i want to disable wordpress in [www.mydomain.com/customscript]

  9. I disabled directory browsing, but still someone can see my directory when they use developer tools in chrome browser. How do I disable in that as well?

  10. I added the line that you said in .htaccess but it showes my directories yet .
    What should I do now??

  11. When I click “Save Changes” on the Permalink Settings page the .htaccess file is updated, erasing the “Options -Indexes” code that I inputted. The code works fine, but I am concerned I will unknowingly delete it while performing some other task. Are there any other dashboard settings changes that I should know about that may affect the .htaccess file and erase the code? Thanks

  12. Huge fan of wpbeginner, Optin Monster – I got so many useful tips and tricks on WP – and I have to say, the site design is just brilliant. And of course, the content here is epicly useful.

    Thanks guys!

  13. Hey! It doesnt seem to work. if i pull an image to another page its opened with a link of: example.com/wp-content/uploads/…
    Any idea? thanks!

    • Hey Daniel,

      Your images and files inside directories can still be directly accessed. However, server will not let someone directly browse a directory and see its contents.

      Admin

      • I would appreciate if you could iterate on this. I had a hard time when trying to get a solution for this issue. There are some ideas based on a htaccess redirecting to a php file that first checks if the user is logged on. Is there any plugin which provides such a function?

  14. Sorry to late ask. I want to know, are these techniques safe to use regarding SEO score ? Hope you answer !

  15. I have been writing this same code for weeks now but my directory remains visible to users. Pls what am doing wrong? Or could it be that my site is still loading from cached contents? Everybody says it is working but my own experience is different. Any help will be appreciated! Thanks in anticipation of your reply.

  16. Is there a way to allow viewing a directory but just hide the Parent Directory link for a specific page? This would be a network share folder that multiple people would access, and have sub folders which would still require a parent directory listing. I just don’t want anyone going above the shared folder.

  17. This didn’t work for me. I tried before and after #END WordPress and didn’t work. I also tried “Options All -Indexes”, but didn’t work either

  18. Really great. today I just faced and thinking how can I disallow like joomla and I found the exact solution.

  19. Thanks so much, was dismayed to see images from my site going to a parent directory :0. This was very helpful and worked well.
    Blessings – A

  20. Thanks for this tutorial. It worked great for hiding my uploads from anyone just wanting to browse that directory. One question, though. Does this by chance turn off the ability of search engines to browse my website. Sorry if it seems like a dumb question. I am a newbie, after all. :)

  21. I added the Options -Indexes code to the htaccess file, however now I am not able to access the site I get a 503 error. Am I doing something wrong? Need help bad!! Thanks

  22. The problem I have is that I can see the directory of this wordpress site, so if you are using this solution then it doesn’t work… (theme wpbv4)

  23. Thank you so much for the tutorial!

    I was very concerned when I discovered some of my theme directories could be browsed. All good now, thanks to your tutorial. I never knew .htaccess packed in so much punch.

  24. Hello Syed Balkhi

    I just noticed that one of your site list25.com having directory browsing enabled on following folder.

    Not sure if that is important to you.

    http://list25.com/wp-includes/
    Have a great weekend and keep doing your good work.

    regards
    KeelAha

  25. Why do I get a blank page, and not an error when I try to access the ../wordpress/wp-content/ or ../wordpress/wp-content/plugins/ ?

    • It may depend on your theme or your hosting environment. Try enabling directory browsing and then access these directories. If you still get a blank page then this means that those directories have a blank index.php file in them.

      Admin

  26. I tested this before I made any changes with a location that didn’t have an index.php or .htm file and yes you can see all of the files. I added the suggested line at the end of the .htaccess. The location now creates a 403 error from the host and not a 404 error from WordPress. I’m running WP 3.8. Is this the expected behavior?

    • How do I do it in Better Wp security.
      I have installed the plugin, but not able to find this feature

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.