WordPress: Redirect 404 To Homepage
404 errors are the part of every website. The web site hosting server will typically generate a “404 Not Found” web page when a user attempts to follow a broken or dead link; hence the 404 error is one of the most recognizable error’s users can find on the website.
WordPress sites can complicate the 404 troubleshooting process as it is a content management system that processes its own internal rewrite array as a part of its permalinks feature. Sometimes 404 are being caused by the web server or by WordPress. You may need to find out whether the issue is a web server-based or WordPress-based.
It is also never recommended to Redirect any or all 404 errors as it can actually be bad for your search engine results.
When a user clicks on a link to a missing page, the web server will send the user an error message such as 404 Not Found. Customizing the contents of the Page Not Found page in any WordPress theme can be tricky, and usually involves editing the 404.php template.
Sometimes dealing with 404 pages can be troublesome for anyone who manages a website. And often figuring out how to handle such errors when using a CMS such as WordPress can be even more challenging, especially if you do not have coding knowledge.
The most obvious damage caused by a 404 error is it increases the bounce rate on your site. Users may assume that it no longer exists on your site at all, and simply looks elsewhere.
If your site has many 404 errors, it’s possible that it will impact in search engine ranking too. If search engine spiders are constantly presented with non-existent pages, they’ll penalize your site for having invalid links. However few error pages may not have any drawbacks.
There are number of plugins that make handling WordPress 404 errors effortlessly but that also mean you need to install the plugin and adding an additional burden on your web host.
Here is a simple code you need to paste 404.php file, which is located in your theme’s folder. If it doesn’t exist, then create a blank php file and paste the following code:
<?php header("HTTP/1.1 301 Moved Permanently"); header("Location: ".get_bloginfo('url')); exit(); ?>
Once done every 404 page will be redirected to the homepage.