Every website owner is facing the problem of 404s, that’s why every web platform like WordPress allows you to create a page for handling 404 errors. Having a 404.php file in your theme file is the best programming practice in web development. If you want to redirect every 404 URL to homepage, this tutorial will show you the best possible ways to tackle it.
Open your 404.php file paste the following code in the file completely. Note, do not include get_header() or wp_footer() or other things if you are editing the page.
<meta HTTP-EQUIV=”REFRESH” content=”0; url=<?php bloginfo(‘url’); ?>”>
header(“HTTP/1.1 301 Moved Permanently”);
Note: This tutorial is for the users who wants to redirect all 404 errors to the homepage. In other case, you can use any WordPress plugin like WP-301 for custom redirect.