How to Redirect all 404 Errors to the Home Page – WordPress

Back when I started using WordPress the default Permalink would look something like this: “https://www.avoiderrors.com/?p=123″.

Then I started reading that by changing the Permalinks to /%postname%/ would help my rankings, so I changed the default permalink to postname, from there on all of my old links generated 404’s errors. I generated over 1,500 404’s error pages, even using the Redirection plugin would take me a very long time to look for each individual link and map it accordingly.

Redirect all 404 Errors to the Home Page

When redirecting 404 you have few good options:

a. You can create a landing page for the 404’s. One that would have a big search so the person who landed there would have a chance to search for it again like this:

Redirect-all-404-Errors-to-the-Home-Page-2

b. Redirect them all to home page.

c. Track your 404 error pages and redirect them accordingly using Redirection plugin. Prefered. If you are a blogger I would highly recommend this option.

All you have to do is from the WordPress dashboard navigate to Appearance -> Editor under Templates select 404.php. Paste the following code in there:

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

That’s it. Now when a user hits a 404 page they’ll be redirected to the homepage.

If you created a landing page rename URL from the code with the landing page URL.

Redirect-all-404-Errors-to-the-home-page-1

Miguel

I started this tech blog back in 2011 as a place to write down processes I took to fix my client systems and network. Now I write some tips and tricks to help others with the tech issues that one might encounter.

You may also like...