The HTTP 404 error is basically page not found error. It can either be client side error or server side server.
In client side error, a user types an URL that is not valid or wrong. In such a scenario, the response from the server side will be null and hence, the user will see a 404 page not found error.
On the other hand, when a client types an URL or goes to an URL from social media pages or search engine to your website but somehow that page is missing from your server, he will see page not found 404 error for no fault of the person.
WordPress redirects broken links or missing URLs to a special 404 error page, which displays an error message stating that the requested page could not be found. While the 404 error page does have a number of links to important pages but many of you would prefer to have all 404 errors redirected to the blog’s homepage instead.
If you are one of them, then you stay right here. In today’s WordPress tutorial, we will explain how to redirect 404 to the homepage of your website.
Before you proceed to the methods, we would recommend you to access your existing 404.php file and rename it to something different. For example, you can rename it to 404-old.php. By this way, you would remember the original 404.php file and it would be easier for you to revert back to the previous setting.
Once you are done with that, open notepad, add below the code and save the file as 404.php.
<?php header("HTTP/1.1 301 Moved Permanently"); header("Location: ".get_bloginfo('url')); exit(); ?>
Now, upload your new 404.php file to your blog’s active theme folder using Cpanel or FTP. The path is typically /wp-content/themes/your theme name/
That’s all. From now onwards if any of your users hit a 404 page then they will be redirected to your website homepage.
I believe this WordPress tutorial was helpful for you to redirect 404 to the homepage of your website.
Note: There are many plugins available in the WordPress directory to get this job done. You can use any of them if you are not comfortable doing manually.