How to Redirect 404 page to the Home Page in WordPress without plugin

As we all know, 404 page is an important part of every website but if that page is not in your website then it may affect your website’s SEO.



So here first I will tell you what actually 404 page is?

The 404-page error is an HTTP status that means the page you are trying to reach is not available. Some people make their custom 404 page to show visitors that this page is moved permanently or no more available. Here you can see a perfect example of custom 404 page – Snapdeal

So, if you haven’t created that page on your website or want to redirect that to the homepage you just need to add/edit/create a file in your website named “404.php“.

Steps to redirect 404 to homepage –

  1. Open your website’s Cpanel and go to its root files.
  2. There you will find a page named “404.php“.  If in case, that page is not there, you can create a new 404.php page and then you need to add a code in it which is mentioned below.
  3. After adding that code, you need to save that file.
  4. As you will save your file, your all 404 error pages will start redirecting to the homepage without any error. You may check that as well. 🙂





Code –

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

 

Hope after this brief explanation you have understood this perfectly but if you still have any doubt or query please let me know in the comments. I will happy to answer them. 🙂

Leave a Reply

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