February 1, 2015

How to redirect your WordPress website’s 404 page to your homepage

deeperlook-brisbane-wordpress-404

Recently, we were contacted by a client asking how they could have their visitors redirected to their WordPress website’s homepage instead of the 404 page. And even though this is easy to do, we wanted to explain the potential visitor headache behind this process.

Many SEO gurus believe that using a 301 redirect to take your visitors to your WordPress homepage is the safest option for retaining your incoming link strength however, it isn’t always the best form of practice for your visitors.

We believe that if your a small to medium size business website, it is more important to actually show your visitors a 404 page than to redirect them. Why? Lets say you try to visit a link or revisit a webpage and expect to be taken to that particular page but actually end up on the homepage. You’d be confused and a little frustrated, right? Well, that is exactly what you visitors will be thinking.

However, in the case that you have a webpage that is receiving a high volume of backlinks and have decided to remove that page, setting up a 301 redirect is more than acceptable to help redirect search engine bots and visitors to an alternative page. This page doesn’t always need to be the homepage, it could be your blog page or a page that you feel would be a nice fit as a replacement.

With that said, if you’re still interested in setting up redirect from the 404 page to your homepage in WordPress, we’ll explain how.

  • Login to your dashboard.
  • Go to Apperarance -> Editor -> 404.php
  • Copy the code already on the page to a notepad file (just so you have a copy of the original code in case an error appears).
  • Copy the code below and replace 404.php file code with it.
  • Test a your 404 page redirect and you’re done.

<?php
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: “.get_bloginfo(‘PLACE YOU HOMEPAGE URL HERE’));
exit(); ?>

The code above now tells your internet browser that the page you are looking for no longer exists and you’ll be redirected to the homepage.

If you have any questions about the tutorial above for redirecting your WordPress website’s 404 page to its homepage, please don’t hesitate to contact us.