How to Redirect 404 Pages to the Home Page
This one is useful for SEO purposes – I found it when searching for “htaccess 404 redirect to homepage” and it works great.
NOTE: I used to use this a lot, but it does seem better now to not send these redirects to the home page, but instead just show a really good 404 page that is helpful – one with search, your site design, and popular links. But, just in case, I’m keeping this page up in case someone needs it.
This is another, great redirect with high value. You can redirect all 404 pages to your home page and it’s a 301 redirect, which passes on the link juice. Doing this can often result in a big boost in rankings if your webmaster has been a little careless or if you bought a domain just for the link juice and you want to pass all the juice on – not just the home page. Or you could say you’re passing on all the URL authority instead of just the domain authority. (Source)
ErrorDocument 404 https://www.yourdomain.com/
And then if you’re using WordPress and want to redirect all 404 pages to the home page, the code above might not work since WordPress might use a 404 page already in your theme.
In that case, open up the 404.php file in your theme and use this code instead of what’s there now (create a child theme to prevent this being overwritten).
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
exit();
?>📄 Download a PDF of This Article
