How to Redirect All 404 Errors to Homepage in WordPress
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.
Hey thanks a lot for the info,
for last few days i was getting annoyed by 404’s in my website.
really useful stuff.
nice artical….. thank u
I don’t know much about 404 error pages because I had started my blogging career recently.
But somewhere I read that If any blogger or writer deleted the existing web page then the URL of that web page becomes 404 URL and that page becomes 404 page.
It is also said that Google don’t like 404 page so I checked my site whether I had any 404 page or not then I found few of the 404 error pages on my site also.
But Now after reading this post, I can easily handle these pages.
Thanks for sharing such a helpful post with us. 😀
Yeah, @David.. Thanks for appreciative comment by the way. And keep reading our blog.
Thanks for great post. I have done this after reading this in my blog. But I want to redirect all 404 error page to custom domain. How to do it? please give me reply.
That thing can be done by redirect rules from cPanel.
Thanks Bro
Its good thanks brother… can you tell me another is good??
https://wordpress.org/plugins/remove-query-strings-littlebizzy/
thanks bro for feedback 😉