404 is a very bad error which tells the web user about the page which is being accessed in is no longer exist. 404 page not found error could be exist in any website and can slow down your site as well as hurt your SEO (search engine optimization) performance. No matter how good is your SEO but if you are not providing your readers what they are looking for and instead the page that your users are looking for went 404 page not found error that can possible hurt your search engine performance.
If you are WordPress user then you should install and optimize SEO by Yoast WordPress plugin that helps you to optimize basic SEO for your blog. But in this article you will learn how to add 301 redirection on 404 not found pages so they can just redirect to homepage without messing up your search performance.
There are 2 ways that you can redirect 404 page not found errors to homepage either by using a WordPress plugin or by using theme’s 404.php file.
2 Ways to Redirect All 404 Errors to Homepage in WordPress
1. All 404 Redirect to Homepage
All 404 redirect to homepage is a simple WordPress plugin which works out of the box and redirect all not found pages to homepage of your WordPress site. By using this smart plugin, you can fix all 404 error links by redirecting them to homepage using the SEO 301 redirection.
2. Using Theme’s 404.php file
First of all you have to open up your theme’s 404.php file of your activated theme and add the following lines of codes that file. However, if the 404.php file doesn’t exist, then create a blank php file and put the following code in there:
<?php header("HTTP/1.1 301 Moved Permanently"); header("Location: ".get_bloginfo('url')); exit(); ?>
This is how we actually redirect all 404 errors to homepage in WordPress.