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の投稿が404エラーを返すのを修正する方法(ステップバイステップ)

WordPressの記事を開こうとしたら、404エラーが表示されたことはありませんか?時には、私たち自身のWordPressサイトで作業しているときや、ユーザーをサポートしているときに、そのような経験をすることがあります。

このエラーは、WordPressの管理画面やブログにはアクセスできるが、特定の記事を開こうとすると「404 Not Found」というメッセージが表示される場合に発生する。

しかし、この問題を解決する回避策をいくつか見つけました。この完全ガイドでは、404エラーを返すWordPressの投稿を修正する方法をご紹介します。

How to fix WordPress posts returning 404 error

WordPressの投稿が404エラーになるのはなぜですか?

WordPressで404「Page Not Found」エラーが表示される原因はいくつかあります。以下のような原因が考えられます:

  • プラグインやテーマの競合:サイトにインストールしたプラグインやテーマが、WordPressのパーマリンク処理に干渉することがあります。これはリンク切れや404エラーにつながる可能性があります。
  • カスタムコードの問題: カスタマイザーコードをサイトに追加している場合、パーマリンクに影響するエラーやその他のコンフリクトがコード内に存在し、投稿に404エラーが発生している可能性があります。
  • .htaccessファイルの問題:.htaccessファイルは、WordPressがURLをどのように構造化するかという役割を果たします。このファイルが破損していたり、見つからない場合、投稿やページに404エラーが発生する可能性があります。

404エラーのWordPress投稿をすべて見つける方法

解決策を紹介する前に、このエラーが1つまたは2つの投稿で起きているのか、複数の投稿で起きているのかを把握するのがよいでしょう。そうすることで、問題の範囲を特定し、最も適切な解決策を選択することができます。

これを把握する簡単な方法の1つは、Google Search Consoleを使用することです。まだGoogle Search Consoleにサイトを送信していない場合は、Google Search ConsoleにWordPressサイトを追加する方法についてのガイドをお読みください。

Googleボットがあなたのサイトをクロールし、インデックスした後、Google Search Consoleはあなたのサイトのパフォーマンスに関する詳細な情報を提供します。

どの投稿が404エラーを返しているかを調べるには、Search Consoleのダッシュボードにログインします。そして、「ページ」レポートに移動すると、すべてのエラーの詳細なリストが表示されます。

Google Search Console Pages Report

詳細については、Google Search Consoleを使用してウェブサイトのトラフィックを増やすためのヒントリストをご覧ください。

それでは、404エラーを返すWordPress投稿を修正する方法を見ていきましょう。以下のリンクから、さまざまな解決策にジャンプできます:

404エラーを自分で修正する時間がない?WPBeginnerプロサービスがお手伝いします!404エラー、リンク切れ、リダイレクトの問題などを専門家に依頼することができます。WordPress の問題にストレスを感じるのはやめて、問題を解決しましょう!WordPress 緊急サポートサービスを今すぐご予約ください!

方法1:プラグインやテーマのコンフリクトやカスタムコードの問題をチェックする

WordPressウェブサイトに追加したプラグイン、テーマ、カスタムコードがパーマリンクに干渉したり、競合を引き起こしたりして、404エラーにつながることがあります。私たちのデモサイトでツールをテストしているときに、私たち自身も経験したことがあります。

この問題を解決するひとつの方法は、プラグインを一時的に無効化することです。プラグインはWordPressがリンクを処理するのを邪魔することがあります。

プラグインを無効化したら、プラグインを1つずつ再有効化し、各プラグインを有効化した後に404エラーが再び表示されるかどうかを確認します。特定のプラグインを有効化した後にエラーが表示される場合は、そのプラグインが原因かもしれません。

その後、そのプラグインに関連するソリューションをGoogleで検索したり、サポートのためにプラグイン開発者に連絡することができます。

同様に、WordPressテーマが競合を引き起こしている可能性もあります。

確認するには、一時的にTwenty Twenty-ThreeやTwenty Twenty-FourのようなWordPressのデフォルトテーマに切り替えることができます。必要なのは、外観 テーマに 行き、デフォルトテーマの「有効化」をクリックするだけです。

Activating a default WordPress theme

デフォルトテーマで404エラーが消えた場合、現在のテーマと競合している可能性があります。その場合は、テーマのトラブルシューティングを試すか、別のテーマの使用を検討してください。

WordPressテーマのエキスパートが選ぶ、おすすめの人気テーマをご覧ください。

最近サイトにコード・スニペットをインサーターした場合、コードにエラーがあり404エラーが発生している可能性があります。追加したコードをよく見て、間違いがないか確認してください。

WordPressにコードスニペットを追加する最も安全な方法は、WPCodeプラグインを使用することです。このプラグインを使えば、テーマファイルを直接操作することなくカスタムコードを挿入することができ、サイトが壊れるリスクを減らすことができる。

さらに、WPCodeはあなたのコードにエラーを発見するたびに、自動的にスニペットを無効化し、それを確認するように要求します。また、テストモードを使用すると、ライブサイトにプッシュする前に、コードが動作するかどうかを確認することができます。

WPCode error warning

いずれの解決策もうまくいかない場合は、パーマリンク設定のトラブルシューティングを行う次の方法に進んでください。

WordPressの投稿は、.htaccessファイルのリライトルールに問題があるため、404エラーを返すことがあります。ほとんどの場合、パーマリンクの設定を更新することで問題を解決できます。

WordPress管理画面の設定 ” パーマリンクに移動し、「変更を保存」ボタンをクリックするだけです。

Check Permalinks

パーマリンク設定そのものを変更する必要はありません。パーマリンク設定を更新し、書き換えルールをフラッシュします。

ほとんどの場合、この解決策はWordPressの投稿404エラーを修正します。しかし、もしうまくいかない場合は、.htaccessファイルを手動で更新する必要があるでしょう。

方法3:WordPressの.htaccessファイルを更新する

作業を始める前に、WordPressの.htaccessファイルをバックアップしておいてください。何か問題が発生しても、元のファイルを簡単に復元することができます。

ここで、FileZillaのようなFTPクライアントまたはWordPressホスティングダッシュボードのファイルマネージャーアプリを使用してサーバーに接続する必要があります。

次に、/wp-content/や/wp-includes/などのフォルダーと同じ場所にある.htaccessファイルを見つけて編集する必要があります。

ファイルを右クリックして「ファイルの権限」を選択するだけです。

.htaccess file permissions

権限を666に変更すれば、ファイルを書き込み可能にできる。

数値」ボックスに「666」と入力し、「OK」をクリックする。

Change file attributes for the .htaccess file to 666

その後、チュートリアルの最初の方法の手順を繰り返す必要があります。これを行ったら、権限を660に戻すことを忘れないでください。

ファイルを編集してコードを追加することもできる。

Edit .htaccess file

.htaccessファイルをテキストエディターで開いたら、このコードを挿入するだけです:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

方法4:ホスティングサービスに問い合わせる

上記のいずれの解決策でもWordPressの投稿が404エラーを返してしまう場合は、WordPressのホスティングサービスプロバイダーに連絡することをお勧めします。ホスティングプロバイダー側のエラーかもしれませんし、トラブルシューティングを手伝ってくれるかもしれません。

WordPressのサポートを正しく依頼し、サポートを受ける方法については、こちらのガイドもご覧ください。

方法5:mod-rewriteを有効にする(WordPressのローカルインストール)

テスト目的でローカルサーバーを使用している場合、MAMP、WAMP、XAMPPサイトのApache設定でmod_rewriteを有効化する必要があります。

これにより、WordPressはきれいなURLを生成し、ローカルサーバー上の投稿やページの404エラーを防ぐことができます。

これをどのように行うかは、使用しているプラットフォームによって異なります。XAMPPを使用している人は、コントロールパネルを開き、Actions内の「Config」ボタンをクリックします。そして、「Apache (httpd.conf)」を選択してください。

The Apache (httpd.conf) menu on XAMPP

次に、#LoadModule rewrite_module modules/mod_rewrite.soという行を見つけ、’#’を削除してアンコメントする必要がある。

これでmod_rewriteがロードされる。

Finding the rewrite_module on httpd.conf file

次に、AllowOverride Noneのインスタンスをすべて見つけ、AllowOverride Allに変更する。

All’ はすべてのディレクティブを上書きできることを意味します。

Changing AllowOverride None to AllowOverride All

完了したら、httpd.confファイルを保存して閉じます。その後、XAMPPコントロールパネルでApacheモジュールの「Stop」をクリックし、再度「Start」をクリックして再起動します。

その後、管理ダッシュボードに戻り、パーマリンクが機能しているか確認してください。

動画チュートリアル

視覚的な説明が必要な場合は、以下のビデオをご覧ください。

Subscribe to WPBeginner

この記事がWordPressで404エラーを返す投稿を解決するのにお役に立てば幸いです。また、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

770件のコメントLeave a Reply

  1. Thank you very much for precious article that is useful to fixed my website problem.. i always prefer your web solution regarding in problem in wordpress cms.

    Thank you..;.

  2. Just wanted to leave a thank you comment! Your guides on WordPress are second to none! I have learnt so much reading your blog and every time I Google a problem..I am looking for your website and that is where I will click! Great and simple instructions even on the most complicated WordPress issues…you are awesome! Thanks.

  3. This totally worked! I just updated my PHP and dashboard and home pages was accessible but not any of my post pages.
    Thx

  4. Thank You so much it saved my life! I had to move my WordPress website to a new server and it took me a whole day to fix everything. I wish WP had an easy way to do this. :)

  5. I tried everything in the article with no success. What I ended up doing was choosing a different Permalink structure and saving it, and then going back to the structure I wanted and saving it. Then all was well.

  6. I accidentally deleted .htaccess file when doing 301 and got the 404 not found error. Your tutorial came to my rescue. Just by saving the permalinks and it worked. Thank you.

  7. Wow, I’m shocked at how fast this worked. I recently migrated my site from a subdomain to the root domain and none of my links were working. All I did was go to permalinks in settings and click “save changes.” That was all. Wow. And I was really scared I’d broken something. Thank you.

  8. Hi, thanks for the tips. I still can’t seem to fix the error. Have reset Permalinks, installed a redirect plugin (doesn’t help if wanting to redirect to the homepage). I can’t work out how to alter the .htaccess and not really confident to do it. Any other suggestions?

  9. THANK YOU for this post! I had a primary domain that I let go and needed to move two sites on my hosting plan…. 1 to the primary domain position and 1 to an addon domain position which was formerly a subdomain position. I broke a lot of stuff. With some logical thought, I got most of it all back… EXCEPT all the pages on the primary domain site couldn’t be viewed on the live site once you clicked on them or the menu links. The home page loaded beautifully, but when you clicked a post or link… the errors popped up. This trick resolved those issues… so THANK YOU again! You saved the day!

  10. I just change the permalink directly and it shows 404 error I couldn’t access my website it redirects me to another site which is not mine

    • You would want to reach out to your hosting provider to ensure your domain is set up properly and there isn’t any malicious code on your site.

      Admin

    • For nginx, at the moment you would want to reach out to your hosting provider and they should be able to assist.

      Admin

  11. I’m busy building a website via wordpress & cpanel. I by accident deleted the url in my dashboard. Now I don’t get even access. Is their any way to fix it.

  12. After saving changed for the permalink, it still returned the 404 error. Then I used the clear cache WP button at the top and the problem was solved.

  13. Thanks so much for this post. You are a lifesaver. Clicking ‘Save Changes’ on Permalinks under Settings did the job for me.

  14. I have issues on 404 Page not found.
    I tried updating the permalinks but still not working and I also checked the .htacess file in our server and it’s the same on the above sample. But still not working.

    • You may want to reach out to your hosting provider to ensure there are no issues on their end that could be a part of the issue

      Admin

  15. Just a quick note to say thank you so much! I had just activated a CDN (learning as I go) and thought I had broken my site and went searching everywhere but here was the answer…phew!

  16. Hi!

    I’ve added the htaccess script, updated my wordpress but still I need to resave the permalinks. Any other solution?

    Thanks!

  17. i have 404 error but cannot acces neither the site or the wordpress. how can you access wordpress admin to solve the problem??

  18. on clicking save changes my problem Resolved, WP beginner is a part of my journey to learn WordPress more and more.

  19. So I checked all solutions and comments. I have same issue with a twist. I can see the pages when I am changing it to use the Page ID but not when I am selecting the Post-Name? Any solution to this? I know its weird.

    • You may want to delete the current htaccess file and if that does not fix the issue, reach out to your host to ensure there isn’t an underlying error causing the problem.

      Admin

  20. Hello,
    I just wanted to let you know that your website is of such great help ! I built my first WordPress website and I managed to resolve many issues thanks to your articles. Thank you !

  21. Hello Guys,

    I have been facing this issue for the last three days after migrating a new site from my localhost to an online CPanel server. Having tried a million and one option from various forums, none of them could work at all. The only solution that seems to work is disabling Mod_Security in the CPanel. I just did it and it works like a champ. Thanks

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.