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

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

Last updated on by
Follow WPBeginner on YouTube
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:

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

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 lovers 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 »
  • dcaryll

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

  • Roy

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

  • P.D.

    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?

  • Vishal

    Thanks dude…. :)

  • Prasanna

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

    Thanks a lot.

    :)

  • marco

    Thanks that help a lot.

  • Dilpreet Bhatia Music

    Wow – That Was easy!!

  • Filip Hajek

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

    • Eric

      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-

  • Nikole

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

    • http://www.wpbeginner.com Editorial Staff

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

  • Rakesh

    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.

  • ud

    Thanks for your very useful information

  • Arslanh

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

    • http://www.wpbeginner.com Editorial Staff

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

  • Julien

    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

      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.

  • Andy Feliciotti

    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

    • http://www.wpbeginner.com Editorial Staff

      What is this extension called?

  • http://twitter.com/clarklab Clark Wimberly

    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.

    • http://www.wpbeginner.com Editorial Staff

      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.