How to Redirect 404.php Page To the HomePage in WordPress

Every website owner is facing the problem of 404s, that’s why every web platform like WordPress allows you to create a page for handling 404 errors. Having a 404.php file in your theme file is the best programming practice in web development. If you want to redirect every 404 URL to homepage, this tutorial will show you the best possible ways to tackle it.


Method 1:

Open your 404.php file paste the following code in the file completely. Note, do not include get_header() or wp_footer() or other things if you are editing the page.

[code type=”php”]



<meta HTTP-EQUIV=”REFRESH” content=”0; url=<?php bloginfo(‘url’); ?>”>




Method 2:

[code type=”php”]

header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: “.get_bloginfo(‘url’));


Note: This tutorial is for the users who wants to redirect all 404 errors to the homepage. In other case, you can use any WordPress plugin like WP-301 for custom redirect.

Duan Lingxin

Duan Lingxin

Content crafter and chief editor at Scratching Info. Also regular contributor on other major online tech platforms. Security Specialist by day and a writer by night, he does his best to instill his knowledge about tech while delivering inspiring and life changing resources through his writing,

More Posts - Website

6 thoughts on “How to Redirect 404.php Page To the HomePage in WordPress”

  1. I don’t know much about 404 error pages because I had started my blogging career recently.

    But somewhere I read that If any blogger or writer deleted the existing web page then the URL of that web page becomes 404 URL and that page becomes 404 page.

    It is also said that Google don’t like 404 page so I checked my site whether I had any 404 page or not then I found few of the 404 error pages on my site also.

    But Now after reading this post, I can easily handle these pages.

    Thanks for sharing such a helpful post with us. 😀

  2. Indeed a Great post about 404 redirection.

    It is said that 404 not found pages or broken pages aren’t good for any blog because It gives bad user experience and It also affects badly in search engine rankings.

    Search engine like Google never wants to redirect their users to a page which shows not found errors. Right?

    So It is must to redirect these 404 pages to either another relevant page or to homepage.

    I can remember when I started my 1st blog then I didn’t have any idea that on which niche I should write. So I used to write on different different topics and later deleted those articles when move to another niche.

    In this way, I created so many 404 not found pages in my blog and one day, I realized that Webmaster tools is showing so many not found errors.

    When I saw that, I scared because I didn’t knew about these pages at that time. Then I did research and fixed those pages.

    Thanks for sharing such a wonderful tutorial. 😀

  3. Very informative post. I loved especially how you explained the method to redirect 404 pages to homepage in WordPress. I never tried this method. Thanks for telling me about it.


Leave a Comment