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

WordPressで404ページをホームページにリダイレクトする方法

編集メモ: WPBeginner のパートナーリンクから手数料を得ています。手数料は編集者の意見や評価に影響を与えません。編集プロセスについて詳しく知る。

WordPressで404ページをホームページにリダイレクトしたいですか?

404 ‘Not Found’ページをサイトのトップページにリダイレクトすることで、直帰率を減らし、ユーザーがサイト内の他の有益なコンテンツを発見する権限がありません。

この投稿では、WordPressで404ページをホームページにリダイレクトする方法を紹介します。

How to Redirect Your 404 Page to the Home Page in WordPress

なぜ404ページをWordPressのホームページにリダイレクトするのか?

ユーザーがWordPressサイトに存在しないページを訪問しようとすると、WordPressは代わりに404エラーページを表示します。

このページの文言や外観は、使用しているテーマによって異なります。

Default WordPress 404 page

初期設定の404ページにランディングしたユーザーのほとんどは、すぐにサイトを離れてしまいます。これは、サイト全体の直帰率を高め、検索エンジンのランキングに悪影響を及ぼします。

そのため、時間をかけてカスタム404ページを作成する必要がある。しかし、そうするまでは、このチュートリアルのショートカットを使ってユーザーをホームページにリダイレクトすることができます。

完璧な世界では、特定の404エラーリクエストを最も関連性の高いページにリダイレクトすることもできます。

それでは、すべての404エラーをホームページにリダイレクトする方法を見ていきましょう。ここでは、2つの方法と、個別のページにカスタマイザーリダイレクトを作成する方法を紹介します:

方法1:WordPressですべての404エラーをホームページにリダイレクトする

この方法では、All In One SEO for WordPress(AIOSEO)を使用する。このプラグインは、リダイレクトの設定や検索エンジン向けのコンテンツの最適化などを可能にする、WordPressのSEOプラグインとして最適です。

最初に行う必要があるのは、All In One SEO (AIOSEO)をインストールして有効化することです。詳しくは、WordPressプラグインのインストール方法のステップバイステップガイドをご覧ください。

注:All In One SEOには無料版もありますが、RedirectはProアドオンなので、今回はPro版を使用します。

プラグインを有効化したら、All In One SEO ” Redirectsに移動する必要があります。

まだリダイレクトを設定していない場合は、「リダイレクトを有効化する」ボタンをクリックしてください。

Activating Redirects in All in One SEO

All In One SEOのRedirectsモジュールがインストールされます。

次に、ページ上部の「設定」タブをクリックします。このページでAIOSEOのリダイレクトを設定することができます。

The AIOSEO Redirects Settings Page

高度な404設定」セクションを見つけるまでページをスクロールする必要があります。トグルボタンが青くなるようにクリックして、このセクションを有効化してください。

これで、さらにいくつかの設定が表示されます。Enable default 404 redirect’ボタンをオンに切り替えてください。その後、’ホームページ’オプションが選択されていることを確認してください。

Enabling Default 404 Redirect in AIOSEO

カスタムURL’オプションもあることに注目してください。これにより、404エラーを任意の投稿やページにリダイレクトすることができます。ページの上部または下部にある「変更を保存」ボタンをクリックして、設定を保存することをお忘れなく。

これで、訪問者があなたのサイトに存在しないURLにアクセスしようとすると、初期設定の404ページが表示されるのではなく、ホームページが表示されるようになります。

方法2:コードを使用してすべての404エラーをホームページにリダイレクトする

プラグインを使用したくない場合は、シンプルなコードスニペットを使用して、すべての404ページをホームページにリダイレクトすることができます。

この方法では、WordPressファイルにコードを追加する必要があります。WordPressにスニペットを貼り付ける方法については、初心者向けガイドをご覧ください。また、WordPressテーマのテンプレート階層についてのガイドもご覧ください。

まず、WordPressテーマ・フォルダーに新規ファイルを作成し、404.phpという名前を付けます。すでにテーマに404.phpファイルがある場合は、そのファイルを編集してください。

このファイルを編集するには、FTPクライアントまたはファイルマネージャーツールでWordPressホスティングアカウントに接続する必要があります。

FTP 404 php file

サイトに接続すると、WordPressのテーマフォルダにある404.phpファイルが表示されます。

404.phpファイルの最初の行に以下のコードを追加する必要があります:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
exit();
?>

次に、404.phpファイルを保存し、FTPまたはホスティングコントロールパネルを使用してテーマディレクトリに再アップロードします。

ページが見つからない場合、404ページが表示されるのではなく、WordPressのホームページにリダイレクトされます。

ボーナス:AIOSEOでカスタム404ページリダイレクトを設定する

404エラーに対処する最もSEOに適した方法は、訪問者をホームページだけでなく、最も関連性の高いページにリダイレクトすることです。

All In One SEOプラグインのRedirects機能は、すべての404ページエラーを追跡し、WordPressでスマートな404ページリダイレクトを設定することもできます。

方法1に従ったときにAIOSEOをインストールして有効化したのであれば、All In One SEO ” リダイレクトのページに戻り、「設定」タブをクリックするだけです。

次に、「ログ」セクションが表示されるまで下にスクロールします。404ログは、訪問者があなたのサイトに存在しないページを訪問するために使用しようとしたURLの記録です。

404ログ’が青く見えるようにトグルがオンになっていることを確認してください。プラグインがログを記録する期間をドロップダウンメニューから選択することもできます。

Enable 404 logs

次に進む前に「変更を保存」をクリックするのをお忘れなく。

その後、「404ログ」メニューオプションをクリックして、最後にアクセスされた404ページを見ることができます。

ログ記録を有効化したばかりなので、すぐには何も表示されないかもしれないことを忘れないでください。有益な洞察が表示されるまで、最大24時間待つ必要があるかもしれない。

Click 404 logs menu option

URL」カラムには、ユーザーが訪問しようとしたが存在しなかったページが表示されます。

リダイレクト」列の「リダイレクトを追加」リンクをクリックすると、これらの URL を既存のページにリダイレクトできます。リダイレクト情報を入力するドロップダウンが開きます。

最良の結果を得るには、元のクエリーに対して最も関連性の高いページを「ターゲットURL」ボックスに入力し、「リダイレクトを追加」をクリックする必要があります。

Add home page redirect

例えば、WordPressブログの始め方に関するチュートリアルを削除し、新しいチュートリアルを書いた場合、古いURLをホームページではなく新しいブログ投稿にリダイレクトするのがベストです。

複数の404ページリダイレクトを追加するには、上記と同じ手順を踏むだけです。

一般的に、404ページを永久にホームページにリダイレクトしたくないことを覚えておいてください。よりコンバージョンの高いカスタマイザー404ページを作成するか、ユーザーを関連ページに誘導するリダイレクトを個別に設定するまでの一時的な解決策としては最適です。

WordPressの404エラーに関するエキスパートガイド

WordPressで404ページをホームページにリダイレクトする方法はおわかりいただけたと思いますが、404エラーの処理方法に関する他のガイドもご覧ください。

WordPressで404ページをリダイレクトする方法について、この投稿がお役に立てば幸いです。究極の WordPress SEO ガイドや、カスタマイザーで 404 ページを作成するのに最適な 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.

情報開示 私たちのコンテンツは読者支援型です。これは、あなたが私たちのリンクの一部をクリックした場合、私たちはコミッションを得ることができることを意味します。 WPBeginnerの資金源 をご覧ください。3$編集プロセスをご覧ください。

Avatar

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.

究極のWordPressツールキット

ツールキットへの無料アクセス - すべてのプロフェッショナルが持つべきWordPress関連製品とリソースのコレクション!

Reader Interactions

66件のコメント返信を残す

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. Ralph says

    I have 2 or 3 blog posts that had to be deleted, but the urls are still present on Pinterest, forums, etc., so I redirected 404 to my homepage in hosting settings to not lose traffic. However, for any other non deleted 404 I have my own “sorry” info and search bar.
    I really appreciate good 404s on people’s websites, as this often indicates that they really care. Redirecting to the homepage has its uses, but not every time I think.

  3. Jiří Vaněk says

    I think, but it’s just my personal opinion, that redirecting people to the homepage isn’t good. Instead, it’s better to create a humorous 404 with an apology that reduces visitor frustration and offers interesting content in the form of a 404 page where the latest content of the website or blog can be automatically inserted. This way, the visitor realizes the page no longer exists but also gets the opportunity to laugh at a well-crafted 404 page and receives alternative content as an option for what to do next.

    • WPBeginner Support says

      That is another option, it depends on the site and what type of content but both are valid options :)

      管理者

  4. Mbah Chinedu says

    Hello, the 301 redirect you do at php file in ftp, can’t I use a text to inform user that the page is going to redirect in some seconds and then allow it redirect. At least bounce rate still reduces, because google has no issue with soft 404 or 404 pages

    • WPBeginner Support says

      You can create a page like that if you wanted but we do not have a beginner-friendly method for creating that with PHP.

      管理者

  5. Mark Cavallo says

    very quick and easy trick – saved me a heap of time manualy redirecting with new website. thank you.

  6. Dave says

    Please what if I don’t want it to go to the homepage, how do I set it to another custom page please?

  7. Mudassir says

    Hello WPbeginner team,

    I am using Astra Pro and have already some code in my 404.php. Now my question is, where do I add the above code exactly? Should I remove all that existing code and add yours or how?

    Please help!

  8. Noble A. Ozogbuda says

    Hello please how can i modify this code to redirect all my 404s pages to a specific page, not homepage?

  9. Mohan says

    I have just installed it and did some redirection. I hope it works the way I expect. Anyway, its a nice plugin. Thanks for the helpful post about it.

  10. Jitendra Mahato says

    hi… i want to know that how to redirect the 404 page to a custom page.I want to do that in my blog. Thank you. Hoping your answer. I used this code and doing well.

  11. Drake Bliss says

    If you only want to redirect a specific url path, try this code below. First create a child theme if you do not have one and move 404.php to the the child theme.

    Edit the 404.php page in the child theme and paste this code into the very top of the 404.php page. You can insert more check for other paths you want to redirect,.

  12. yudi cahyadi says

    hi there…i’m using chid theme but it doesn’t exist 404 file,, how to creat 404.php file using child theme not in main theme to insert code ..

    thank you..

  13. Liem Hoang says

    Work perfectly! Thank admin so much, you have been saved my life. My website will no longer get error win WMT.

  14. Malindo My Id says

    wow thankyou so much,, did you know thats my site have been redirect from spammer, makes my eror page 404 found until 1240 not found url. and now I was redirect to my home age.. you are good boys.. thankyou.. I like this page,, so useful for many blogger ..

    Malindo My Id from Indonesia

  15. Shoaib says

    i read anywhere on web that 404s should not be redirected globally to the home page.

    whats your view ???

  16. Sid says

    Is there any way that I can redirect specific 404 pages. Like I created a custom post type and I just want to redirect 404 pages on that post type. Will that be possible?

  17. Kumar says

    This code is causing problem, when i post something new permalink gets shorten and does not contain complete post title.

    What shld i do?

  18. Miguel Guzman says

    I have 1,500 404’s that is because i started using dates on the url at the beginning when i started using WordPress. I changed the permalinks and that’s when the 404 started. is really hard when you have so many redirect to map them individually. its easier to re direct then all to home page.

  19. Riccardo says

    How can you redirect depending on the language the site is displaying?
    My website is in french and english, but when I use your code it goes only to one page for both languages.

    Thank you for your help!

    Riccardo

  20. slango20 says

    this is bad practice, very bad. If you have time to set up a wordpress site, you have time to put 404 Not Found into a 404.php at *least* instead of redirecting to the homepage with no explanation whatsoever

  21. P.D. says

    Does anyone know if the code works as well for multisite installations?

    If so, does the 404 page bounce to the subdomain / subfolder / subsite or the main or root domain / folder / site?

    • slango20 says

      those crawl “errors” are perfectly normal and don’t affect your site’s ranking, just like it’s not a good idea to reply to all sms with the same response just because you received a few spam sms

  22. Filip Hajek says

    There is a cool WP plugin “404 Redirected”, whoch captures 404s for you and let’s you redirect them easily.

    • Eric says

      Thanks for the comment! That helped me out a lot! The article’s has a good solution too but I don’t like messing with my code. Thanks again for the suggestion Flip!

      -Eric Out-

  23. Rakesh says

    It rocks!!! I used the code ( previously my theme given me a custom 404 page template, but I replaced with your few lines). Thank you.

  24. Julien says

    I am really not convinced by the relevance of this. 404 means the page doesn’t exist anymore, 301 is a permanent redirect. Those 2 errors do not mean the same for search engines.

    • Rootpak says

      I agree. I would not recommend redirecting all 404 pages to the home page. From SEO point of view it is not accepyable. It means that every not existing page was moved to home page. It can simply lead to problems how google sees your site.

  25. Andy Feliciotti says

    I use smart 404 extension and I must say it’s amazing, it’ll find a post with a similar URL and redirect to it

  26. Clark Wimberly says

    I should know better, but one time I created an infinite loop using something close to this. It was a site with few pages for mostly logged-in users, so I made my 404 template redirect to the user page. What I had forgotten is that I made my user page redirect to the 404 if you weren’t signed in. Totally my fault, and barely relevant, but there you go.

    • Editorial Staff says

      Hah that’s funny. The only reason why we wrote this code was for a small one-page site which where we didn’t want users to peek around too much. Some folks are just curious and they start running search or checking out feeds etc. So we disabled search, feeds, and redirected 404 to the homepage.

      管理者

返信を残す

コメントありがとうございます。すべてのコメントは私たちのコメントポリシーに従ってモデレートされ、あなたのメールアドレスが公開されることはありませんのでご留意ください。名前欄にキーワードを使用しないでください。個人的で有意義な会話をしましょう。