Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Disable Directory Browsing in WordPress

Do you want to disable directory browsing in WordPress?

Directory browsing can put your site at risk by showing important information to hackers, which can be used to exploit vulnerabilities in your site’s plugins, themes, or even your hosting server.

In this article, we will show you how you can disable directory browsing in WordPress.

How to disable directory browsing in WordPress

What Does Disabling Directory Browsing in WordPress Do?

Every time someone visits your website, your web server will process that request.

Usually, the server delivers an index file to the visitor’s browser, such as index.html. However, if the server can’t find an index file, it may instead show all the files and folders in the requested directory.

This is called directory browsing, and it’s often enabled by default on your hosting server.

If you’ve ever visited a site and seen a list of files and folders instead of a webpage, then you’ve seen directory browsing in action.

A WordPress site with directory browsing enabled

The problem is that hackers can use directory browsing to see the files that make up your website, including all the themes and plugins you use.

If any of these themes or plugins have known vulnerabilities, then hackers can use this knowledge to take control of your WordPress blog or website, steal your data, or perform other actions.

Attackers may also use directory browsing to look at the confidential information inside your files and folders. They might even copy your website’s contents, including content that you would usually charge for, such as ebook downloads or online courses.

This is why it’s considered a best practice to disable directory browsing in WordPress.

How to Check if Directory Browsing is Enabled in WordPress?

The easiest way to check whether directory browsing is currently enabled for your WordPress website is by simply visiting the /wp-includes/ folder link like this: https://example.com/wp-includes/.

You’ll want to replace www.example.com with your website’s URL.

If you get a 403 Forbidden or similar message, then directory browsing is already disabled on your WordPress website.

A website with directory browsing disabled

If you see a list of files and folders instead, then this means that directory browsing is enabled for your website.

A WordPress site with directory browsing enabled

Since this makes your website more vulnerable to attack, you’ll typically want to block directory browsing in WordPress.

How to Disable Directory Browsing in WordPress

To disable directory listing, you’ll need to add some code to your site’s .htaccess file.

To access the file, you’ll need an FTP client, or you can use the file manager app inside your WordPress hosting control panel.

If this is your first time using FTP, then you can see our complete guide on how to connect to your site using FTP.

After connecting to your site, simply open your website’s ‘public’ folder and find the .htaccess file. You can edit the .htaccess file by downloading it to your desktop and then opening it in a text editor like Notepad.

At the very bottom of the file, simply add the following code:

Options -Indexes

It will look something like this:

The WordPress .htaccess file

Once you’re done, save your .htaccess file and upload it back to your server using an FTP client.

That’s it. Now if you visit the same http://example.com/wp-includes/ URL, you’ll get a 403 Forbidden or similar message.

How to disable directory browsing in WordPress

Expert Tip: If you suspect your WordPress website may have been hacked, then see our guide on fixing a hacked WordPress website. Alternatively, you can take a look at our professional hacked WordPress site repair service and hire professional WordPress security experts to clean your website.

We hope this article helped you learn how to disable directory browsing in WordPress. You may also want to see our ultimate WordPress security guide or see our expert pick of the best WordPress security plugins.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

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. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

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

98 CommentsLeave a Reply

  1. Deepak Kumar

    Its work like charm. Article on wpbeginners like ready to go solution. Keep it up.

  2. Ayo

    How do I now solve the 404 error that comes after?

  3. Pradip Singh

    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.

    • WPBeginner Support

      Glad you found our content helpful :)

      Admin

  4. Sourabh

    Will it block CDNs from accessing my website for static content?

    • WPBeginner Support

      No, it will not.

      Admin

  5. sami

    Does this method affect google crawling .. is it SEO friendly?

    • WPBeginner Support

      It should not affect search engines crawling your site.

      Admin

  6. Meera Shaikh

    Thanks its Done

    • WPBeginner Support

      You’re welcome :)

      Admin

  7. Pradeep

    Thanks my friend, I just try this and it’s work.
    You are the genius.

    • WPBeginner Support

      Glad our guide was helpful :)

      Admin

  8. mousam

    Thank you. I applied and it worked.
    You guys are the best source for learning wordpress.

    • WPBeginner Support

      You’re welcome, glad our guide was helpful :)

      Admin

  9. Kevine

    Thank you very much for this. It solved my problem.

    Thanks again.

    • WPBeginner Support

      You’re welcome, glad our guide was helpful :)

      Admin

  10. malika

    Thank you for sharing information!

    • WPBeginner Support

      You’re welcome :)

      Admin

  11. Jonthan

    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.

    • WPBeginner Support

      Yes :)

      Admin

  12. Teresa Cuervo

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

    • WPBeginner Support

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

      Admin

  13. michael

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

    • WPBeginner Support

      No, it would not affect that negatively.

      Admin

  14. Rhen Castrodes

    Thank you. it works

    • WPBeginner Support

      Glad our recommendation was able to help you :)

      Admin

  15. John

    Thank you! It works even now in 2020.

    • WPBeginner Support

      You’re welcome :)

      Admin

  16. Shams

    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

    • WPBeginner Support

      This code should not make your direct links to images and files turn into 404s

      Admin

  17. Bill

    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?

    • WPBeginner Support

      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

  18. Ionel G

    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!

    • WPBeginner Support

      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

  19. Mayur

    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]

  20. Rafael

    Thank you. Worked perfectly for all browsers.

  21. Dipankar

    but wp-content is showing . how to remove it as well.

  22. Deatram

    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?

  23. Faeze

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

  24. Nathan

    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

  25. Tôi Sống

    Awesome, it work very good!

  26. Baggio

    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!

  27. daniel

    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!

    • WPBeginner Support

      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

      • Axel Jebens

        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?

  28. Ünal Hoca

    Thank you

  29. Khalid Mahmud

    Thank you. It’s working…….

  30. Kim

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

  31. Kimmy

    Still works pretty well. Awesome, simple, and working. Thanks!

  32. Charles

    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.

    • Kimmy

      What part are you having trouble on? What is your hosting provider btw?

  33. Lily

    Thank you. Worked like a charm!

  34. Prakash

    This Above Trick Is Not Working Man….

  35. Mike

    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.

  36. Christian Nastari

    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

  37. hrwhisper

    very helpful, thank you very much

  38. nitai

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

  39. Rob Myrick

    This was very helpful and quick – thank you

  40. Anita in SD

    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

  41. Heather Jacobsen

    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. :)

  42. Wasil Burki

    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

  43. Ted

    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)

  44. Rahul

    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.

  45. KeelAha

    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

  46. Logan

    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/ ?

    • WPBeginner Support

      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

  47. Charlie Sasser

    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?

    • Bern

      I have the same issue it shows 403 error not 404. Did you solve this problem?

    • Christian

      Same issue appear, what to do now? using latest version of wordpress.

  48. Abhisek

    Better WordPress Security plugin takes care of that.

    • Govinda

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

  49. Costin

    Hi,

    Could you please tell me if “Options All -Indexes” is the same or better?

    Thank you!

  50. David Trees

    Thanks for this important information.

    Do you mean;

    Here

    Options -Indexes
    # END WordPress

    OR

    # END WordPress
    Options -Indexes

    Thanks for your reply.

    Cheers
    David

      • Ivan R Linares

        Thank you, worked like a charm!

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.