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

WordPressでディレクトリ閲覧を無効化する方法

ディレクトリ・ブラウジングを無効化していないサイトを多く見かけます。残念ながら、この小さなミスがハッカーに機密情報を暴露し、サイトに害を及ぼす可能性があります。

ディレクトリの閲覧により、他人があなたのサイトのファイルやフォルダーを見ることができます。ハッカーはこの情報を使って、プラグインやテーマ、ホスティングサーバーの脆弱性を見つけることができます。

この簡単なステップを踏むだけで、サイトのセキュリティは大幅に向上します。すべてのサイトオーナーが知っておくべきクイックフィックスです。

このガイドでは、WordPressでディレクトリ閲覧を無効化する方法を紹介します。これにより、サイトを保護し、データを安全に保つことができます。

How to disable directory browsing in WordPress

WordPressのディレクトリ閲覧無効化とは?

訪問者がサイトにアクセスすると、Webサーバーはそのリクエストを処理します。通常、サーバーはindex.htmlのようなインデックスファイルをブラウザーに配信します。

インデックスファイルがない場合、サーバーはそのディレクトリの すべてのファイルとフォルダーのリストを表示するかもしれません。ディレクトリブラウジングとして知られているこの動作は、ホスティングサーバでは初期設定で有効化されているのが一般的です。

私たちは、ディレクトリの閲覧がサイトの構造に関する機密情報を暴露する可能性があることを目の当たりにしてきました。この情報は、プラグイン、テーマ、あるいはホスティングサービスの脆弱性を特定するために使用される可能性があります。

訪問者は、ウェブページの代わりにファイルやフォルダーのプレーンなリストを見たときに、ディレクトリブラウジングに遭遇するかもしれません。このような意図しないアクセスは、対処しなければセキュリティリスクにつながる可能性があります。

Directory browsing enabled

ハッカーは、テーマやプラグインを含むサイトのファイルを表示するために、ディレクトリブラウジングを悪用することがよくあります。これらのいずれかに既知の脆弱性がある場合、攻撃者はその情報を使用してサイトを侵害することができます。

多くの場合、ディレクトリの閲覧によって、電子書籍のダウンロードや オンラインコースなどのプライベートコンテンツや有料コンテンツが公開されることもあります。これは、不正コピーや収益の損失につながる可能性があります。

ディレクトリ閲覧を無効化することは、これらのリスクを防ぐためのシンプルかつ効果的な方法です。WordPressサイトの安全性を確保するために、私たちが推奨する最初のステップのひとつです。

WordPressでディレクトリ閲覧が有効化されているか確認する方法

WordPressサイトでディレクトリ閲覧が有効化されているかどうかを確認する簡単な方法は、/wp-includes/フォルダーに直接アクセスすることです。

例えば、ブラウザーにhttps://example.com/wp-includes/ のようなURLを入力してください。

example.comを実際のサイトのドメイン名に置き換えてください。この簡単なテストは、ほとんどのWordPressインストールで機能します。

403 Forbidden」や同様のエラーが表示される場合は、すでにディレクトリ閲覧が無効化されています。これは、サイトの安全性が高まっていることを意味するので、良い兆候です。

403 forbidden page is displayed when directory browsing is disabled

代わりにファイルとフォルダーのリストが表示された場合は、ディレクトリの閲覧が有効化されている。

これは、サイトが悪意のある攻撃にさらされやすくなることだ。

Directory browsing enabled

私たちの経験では、ディレクトリブラウジングを有効化すると、機密情報が公開され、セキュリティリスクが高まります。このような理由から、WordPressでディレクトリブラウジングを無効化し、サイトの安全を保つことが最善です。

WordPressでディレクトリ閲覧を無効化する方法

ディレクトリ・リスティングを無効化するには、サイトの.htaccessファイルにコードを追加する必要があります。

ファイルにアクセスするには、FTPクライアントが必要ですが、WordPressホスティングコントロールパネル内のファイルマネージャーアプリを使用することもできます。

初めてFTPを使用する場合は、FTPを使用してサイトに接続する方法についての完全なガイドを参照してください。

サイトに接続した後、サイトの公開フォルダーを開き、 .htaccessファイルを見つけるだけです。.htaccessファイルをデスクトップにダウンロードし、メモ帳などのテキストエディターで開いて編集することができます。

ファイルの一番下に、以下のコードを追加するだけだ:

Options -Indexes

こんな感じになるだろう:

Added border to an image

完了したら、.htaccessファイルを保存し、FTPクライアントを使ってサーバーにアップロードしてください。

これで完了だ。これで、同じhttp://example.com/wp-includes/ URLにアクセスすると、403 Forbiddenまたは同様のメッセージが表示されます。

403 forbidden page is displayed when directory browsing is disabled

専門家のアドバイス: WordPressサイトがハッキングされた可能性がある場合は、ハッキングされたWordPressサイトの修復に関するガイドを参照してください。または、ハッキングされた WordPress サイトを修復するプロフェッショナルなサービスを選択し、WordPress セキュリティの専門家に依頼してすぐにサイトを修復することもできます。

追加情報

WordPressサイトを安全かつエラーフリーに保ちたいですか?以下の投稿が役に立つかもしれません:

この投稿がWordPressでディレクトリ閲覧を無効化する方法を学ぶのにお役に立てば幸いです。究極のWordPressセキュリティガイド、またはWordPressセキュリティプラグインのエキスパートセレクションもご覧ください。

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.

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

93件のコメントLeave a Reply

  1. Thanks for the advice. On directory browsing, or that I have it enabled, the AIO SEO plugin keeps warning me. I have currently solved the problem by making the folders have an index file that is empty. Is it possible to take this as one of the possible solutions?

      • Thanks for the advice, I finally used the Options -Indexes method now and AIO SEO already reports the problem as solved. Thanks again.

  2. After editing the htaccess file as per the provided guidelines, I do see 403 Forbidden message for /wp-includes/. But I’m unable to see edit any post. Upon editing a post, I see the same 403 Forbidden message. How to solve this?

  3. 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.

  4. 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.

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

  6. 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

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

  8. 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

  9. 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]

  10. 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?

  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!

      • 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. 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.

  15. 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.

  16. 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

  17. 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

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

  19. 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

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

  21. 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.

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.