• Skip to content
  • Skip to primary sidebar

Laplacef

  • Home
  • About Me
  • Blog
    • WordPress
    • Search Engine Optimisation
    • Blogging
    • Page Speed
  • Free Updates
  • Contact
You are here: Home / Wordpress / How to redirect 404 to homepage in wordpress?

How to redirect 404 to homepage in wordpress?

May 12, 2014 by Keyur 21 Comments

This post will cover how to redirect 404 to homepage in WordPress.

It is quite simple. All WordPress installations do have 404 error page built-in with most of the themes however at times the owner of the website or even the users do not like to be on any error page.

In such case, here are the steps outlined for you to give seamless experience to your users by redirecting any error page to the home page.

Login to your dashboard.

Go to “Apperarance” -> “Editor” -> 404.php

Copy the code below in 404.php file and you’re done.

404 to homepage
1
2
3
4
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
exit(); ?>

The code above tells the browser that the page a visitor is looking for no longer exists and hence the visitor is redirected to the homepage.

Reader Interactions

Comments

  1. Scott says:
    May 12, 2014 at 4:43 am

    I don’t have a 404 template on my theme, but it does have a theme setting to redirect 404’s to either home page or blog. I will use this code on some of my other sites. Thanks for the tip.

    Reply
    • Keyur Amin says:
      May 12, 2014 at 10:45 am

      Glad it helps, Scott. Nice to see you after quite some time.

      Reply
      • Scott says:
        May 12, 2014 at 10:48 am

        Yeah, I’ve been busy working on other stuff, but I am coming around when I can to check what else you have for us.

        Reply
        • Keyur Amin says:
          May 12, 2014 at 10:49 am

          It is always good to see you around, Scott. Keep in touch.

          Have a great day ahead.

          Reply
  2. Azza Bruce says:
    May 12, 2014 at 5:58 am

    Are we replacing the current code included in the file and replacing it with the one you provided?

    Reply
    • Keyur Amin says:
      May 12, 2014 at 10:47 am

      Apology for not explaining it better. You need to enter only the provided code in your 404.php file. No other code in that file is required.

      Reply
  3. Josh Fernandez says:
    May 12, 2014 at 6:06 am

    so where in the file do you copy the code? into the first line? the second? where?

    Reply
    • Keyur Amin says:
      May 12, 2014 at 10:48 am

      You have to just delete all the codes in your present 404.php file and enter the provided code in that file.

      Reply
  4. Davis says:
    May 12, 2014 at 11:14 am

    Thanks Keyur for this explanation. It is now clear on how to go about it. I really appreciate on these insights on redirecting the 404 to homepage.

    Reply
    • Keyur Amin says:
      May 12, 2014 at 3:15 pm

      Glad it helps Davis.

      Reply
  5. Kate Bourland says:
    May 13, 2014 at 9:52 am

    so much amazing stuff to learn. This is awesome. Am I reading this correctly? I think that you’re saying that if we change the code in the php file that any time a page shows up with a 404 error, it will be redirected to the home page?

    Reply
    • Keyur Amin says:
      May 13, 2014 at 2:22 pm

      Thanks for your kindness Kate.

      You got it right. Whenever a page shows up with a 404 error, it will be redirected to the home page.

      Reply
  6. Aneeta says:
    May 13, 2014 at 2:48 pm

    Hi Keyur,
    Wow! Thanks for sharing this code for correcting the 404 error. It is certainly an issue with WordPress and pretty scary for newbies like me!

    Your generosity is much appreciated,
    Aneeta

    Reply
    • Keyur Amin says:
      May 13, 2014 at 8:59 pm

      Thanks Aneeta for your kind words.

      Reply
  7. Shane says:
    May 16, 2014 at 12:57 am

    Wow! Thanks very much Keyur for all of the wonderful tips…Love the idea of the ‘one stop shop’ for newbies…ME!

    If you don’t mind I’d love to run a couple of links between our blog…so if anyone is wanting to know about ‘FIXES’ I can refer them on. Are you keen on swapping links Keyur…….I have to say if I’ve got any sticky question I pop back and ask ya.

    Thanks heaps
    Shane

    Reply
    • Keyur Amin says:
      May 16, 2014 at 8:28 am

      Hey Shane, thanks for your comment and kind words.

      As far as link swapping is concerned, I would stay away from it purely because of SEO purpose.

      Reply
  8. Shane says:
    May 26, 2014 at 12:07 am

    I didn’t knew that Keyur….really appreciate the advise…..
    Shane

    Reply
    • Keyur Amin says:
      May 26, 2014 at 8:25 am

      Thanks Shane for your comment.

      Reply
  9. David says:
    February 25, 2016 at 10:34 am

    Hi Keyur

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

    Reply
  10. Kingto says:
    June 10, 2017 at 4:40 pm

    thanks Mr. Key. is it faster to load than 404 plugin?

    I means https://wordpress.org/plugins/404-to-homepage-littlebizzy/

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Free Blog Updates

Your privacy is never compromised.

Most Loved Posts

How To Defer Parsing Javascript in WordPress

How To Make Your Website Load Faster?

24 Ways You Can Make Money Using Your Website

How To Add Custom Sidebars For Each Category In WordPress?

How to redirect 404 to homepage in wordpress?

Make Your Own WordPress Sidebars

How To Remove WordPress Version?

How To Enable GZip Compression in WordPress?

How To Remove Query Strings From Static Resources?

Curtain Raiser – 20 WordPress Training Videos

© Copyright 2014 - 2016 Laplacef. All Rights Reserved