How to Redirect 404 page to the Home Page in WordPress

redirect 404 page WordPress

This article discusses why and how to redirect 404 page to Homepage of WordPress websites.

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.

In such a scenario, it is important to redirect 404 page to the home page in WordPress so that the person can browse other things.

Why Does 404 Error Happen?

There are various reasons why 404 error can happen.

It could be due to the typing mistake of the user when he manually types an URL.

It is important to note that the user must type the domain name and extension correctly else you will not be able to redirect 404 page to the home page in WordPress.

The most likely occurrence of 404 error from server side is when you migrate a website from one domain name to another or when you migrate it from one web server to another.

The chances are more in the second case due to different permalinks structure and other factors.

There are likely to be many broken links that you have to find out and fix, but in the meantime, you can redirect 404 page to the home page in WordPress so that users do not leave disappointed.

This is a better approach than showing the users a customized redirect page which does not serve your purpose, and the users are likely to leave your site and check the same topic on your competitor’s site.

How To Redirect 404 page To The Home Page in WordPress Using Redirection Plugin

The first thing you need to do is install Redirection plugin.

Redirection Plugin

download

You have to go to the Dashboard and from the left menu, select Plugins and then click on Add New option. Search the plugin by its name and install and activate it.

Then go to Tools from the Dashboard and click on Redirection to set it up perfectly.

redirect 404

In the screen shown above, you have to enter the 404 error pages’ URLs one by one in Source URL and add the corresponding new URLs to target URL which could be the home page.

Apart from that, it comes with various options to redirect people according to the source by changing the Match option to URL only, URL and user agents (only for registered users and subscribers) and URL and referrer (only for referring sites).

The last two options will help subscribers, site members or referring sites to go to target URL which may not be the home page and can be something similar to the old page that has got deleted or broken.

Once everything is done, you can check yourself by going to the broken URLs and see the expected result.

The drawback of this method is the fact that you have to know the broken URLs so that you can redirect to home page or any other page for that matter.

404 redirect WordPress

There is a solution for that too. Redirection provides a tab to check the URLs which people are typing wrong and the pages where people are getting 404 error. Accordingly, you can copy those URLs and set the target URLs. As a matter of fact, you can also detect bots that are trying to access each and every page to get a loophole to access your website from this list of 404 URLs. You can block such bots by IP address and take necessary security actions.

One of the best features of this plugin is that fact that if you happen to modify the URL of an existing and published post, the plugin automatically sets a redirection for the old URL which might have been crawled by the search engine.

Another plugin which redirect 404 pages to directly homepage is

All 404 Redirect to homepage plugin

All redirect 404 to homepage WordPress

download

How To Redirect 404 page To The Home Page in WordPress Using Code

If you do not want to take the headache of knowing the URLs of the broken links and then fixing it and just want to redirect your 404 page to home page in WordPress, you have to write the following code.

But before that, you need to connect your FTP to your web server and in the theme’s folder, you will find a file named 404.php. In case you do not find it, you can create one with the same name. Open the file and paste the following.

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
exit();
?>

Save the file and disconnect FTP with the web server. Now, whenever a user types a wrong URL, or he lands in a 404 error web page on your website, he will be redirected to the home page.

Why Should You Fix 404 Error At Earliest?

If your website has 404 error or broken links, Google crawlers will downgrade your website because it is directly impacting user experience.

For example, the search engine result page is showing a post link to the users from your website. When the user clicks on it and reaches your website, he finds out that the page does not exist.

This is what leads to bad user experience. If you could redirect the user to a similar article URL on your website through Redirection plugin or at least send him to your homepage, it would have been better.

Even having a 404 redirect page that will appear for every broken link will do instead of showing an error.

404 redirect WordPress

Furthermore, it creates a bad impression to your subscribers, and they are likely to unsubscribe you if they get too many 404 errors after you have moved your site from one domain to another or from one web host to another.

Therefore, redirect your 404 page to the home page in WordPress at earliest.

Thank you for visiting SKT Themes a place for selecting top WordPress Themes from a list of several hundred templates. Happy Reading and Shopping.

One thought on “How to Redirect 404 page to the Home Page in WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *