Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

How to Redirect your 404 page to the Home Page in WordPress

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
How to Redirect your 404 page to the Home Page in WordPress

404’s are part of every website. A while ago we compiled a list of some pretty cool WordPress 404 designs. When coding a one page site, you might not have the time to create a custom 404 page. In which case, you might as well redirect the 404 page to your site’s homepage. In this article, we will show you how to redirect 404 page to home page in WordPress.

All you have to do is open your 404.php file in your theme’s folder. If it doesn’t exist, then create a blank php file. Paste the following code in there:

header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));

That’s all. Now when a user hits a 404 page will be redirected to the homepage.

Note: This should be used in very specific cases. In most other cases (i.e blogs, portfolios etc), you should track your 404 pages and redirect them appropriately.

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. Liem Hoang says:

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

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

  3. Shoaib says:

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

    whats your view ???

    • WPBeginner Support says:

      We agree that it is not the best practice. However, sometimes it may become necessary for some websites to do that.

  4. Sanjar says:

    Thanks alot

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

  6. Jaswinder says:

    Good and valuable information, this is what I was looking for.


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

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

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


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

  11. jhelum says:

    fantastic… thanks a lot

  12. dcaryll says:

    Appreciate the quick explanation and answer. Thanks for the post.

  13. Roy says:

    I am very grateful for this. You saved me doing 200+ redirects. Worked a treat.

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

  15. Vishal says:

    Thanks dude…. :)

  16. Prasanna says:

    I really thank full to you. My website here after won’t get crawl errors.

    Thanks a lot.


    • 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

  17. marco says:

    Thanks that help a lot.

  18. Dilpreet Bhatia Music says:

    Wow – That Was easy!!

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

  20. Nikole says:

    What if I want t redirect to a specific page not the homepage?

    • Editorial Staff says:

      You can change line 3. Or better use the redirection plugin like we mentioned in the article.

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

  22. ud says:

    Thanks for your very useful information

  23. Arslanh says:

    I did this but it doesn’t seem to work. I have no knowledge of coding so please help me!

    • Editorial Staff says:

      It should work just fine if you follow the article how it is. This is not a very complicated piece of code.

  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.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.