One of the major reasons most people leave a website is 404 errors. Chances of a potential customer or client leaving a website and going to a competitor’s site are very high when they get 404 errors. Apart from losing clients, a website owner can also lose a lot of traffic and possible backlinks all because of 404 pages. This tells you that you should not ignore them and should try to make sure that you do not have 404 errors on your website. The best way to do that is by redirecting the 404 pages to a custom page or the homepage of your website. In this post, we are going to discuss the best ways of redirecting 404 pages to the homepage in WordPress.
What is a 404 Error and What Causes it?
The 404 error is a Hypertext Transfer Protocol (HTTP) standard response code that indicates that although the browser was able to communicate with the server, it was not able to get what the user had requested.
For example, if another website links to a certain post on your website but misspells the link to that post, all site visitors who click on that link will be taken to a 404 page. This might be a potential client and if you had the 404 pages redirected to the homepage, this person could possibly get a chance to learn more about your services and what you offer.
There are a number of issues that can cause 404 errors. However, the most common one is typing wrong URLs on a browser, as mentioned above. Other common causes might include;
- Lost website content. This can occur when a server malfunctions or during a website transfer.
- After updating old blog posts. Most people will usually change the URL of a blog post when they change their title. This means that site visitors who visit your site using the old URL will be taken to a 404 page.
How to Redirect 404 page to the Home Page in WordPress
We are going to talk about two ways through which you can redirect 404 pages to the homepage in this post. They include;
- Using a Plugin
- Writing a custom code
Using a Plugin
This is the best way to redirect 404 pages to the homepage since you will not need to write any line of code. It is advisable to use a plugin to avoid making adverse mistakes when you try doing so by writing code. There are a number of plugins that you can use, they include;
- All 404 Redirect to Homepage
- Safe Redirect Manager
All 404 Redirect to Homepage
All 404 Redirect to Homepage is one of the most popular 404 redirection plugin with more than 200,000 downloads. It is also the simplest to use because it redirects all 404 pages to the homepage, compared to most of the other plugins that require you to manually create redirects for individual URLs. You can get this plugin for free here.
Safe Redirect Manager
Safe Redirect Manager is another plugin that allows you to easily create 404-page redirects. It comes with a simple and easy to use interface that can be used by anyone even those that are not developers. The plugin works by storing redirects as Custom Post Types compared to most of the other plugins that store it in the custom or options table. It comes with a number of options making it one of the best plugins to use. You can get it for free here.
This is by far the most popular 404-page redirection plugins with over one million active installs. It is very easy to use and comes with several other options that I found to be very interesting. For example, you can redirect people using a certain web browser to a certain page. Other conditional redirects include Login status, Referrer, Cookies, HTTP headers, IP address, Server and Page type – redirect if the current page is a 404 page – among others.
How to Redirect 404 page to the Home Page using All 404 Redirect to Homepage
Step 1: Installing and Activating the Plugin
To get started, we will first install the All 404 Redirect to Homepage plugin. You can do so by either downloading it from WordPress.org or by logging into your WordPress admin dashboard and navigating to Plugins > Add New and then searching for the plugin.
After the installation is completed, make sure to activate the plugin.
Step 2: Customizing the Plugin
Now that the plugin is installed and activated, we will need to customize it and set the redirection rules. To do that, visit the admin dashboard of your WordPress website and go to the Settings section then click on All 404 Redirect to Homepage.
This will take you to the plugin customization page. Here, click on the 404 Redirection Status dropdown menu and select Enabled to enable the plugin, as shown below. After doing that, you will be required to enter the homepage URL of your website on the “Redirect all 404 pages to” section. The plugin will have your homepage URL here. You can add any other custom URL on this field.
Click on the Update Options button after you are done with making the changes. All the 404 pages will now redirect to the homepage in this case. To make sure that everything works well, go ahead and test the changes. You can do that by visiting your website with a URL that does not exist.
Redirecting 404 pages to the Homepage using Code
If you do not want to use a plugin to redirect 404 pages to the homepage, you can do that by writing code. To do that, you will need to log in to your server and visit the Public HTML folder or the folder that has your website files. You can also do this using an FTP file client such as Filezilla to access your website files. The other way is by logging in to the WordPress dashboard and navigating to Appearance > Theme Editor.
Whichever method you use, look for a file called 404.php or create one if it does not exist then add the following code;
<?php header("HTTP/1.1 301 Moved Permanently"); header("Location: ".get_bloginfo('url')); exit(); ?>
Once that is done, save the changes. Now, site visitors will be redirected to the homepage when they hit a 404 error.
You can avoid the 404-page error by following these few steps on this post. It will not even take you more than a minute. If you have better ways of doing this, kindly share in the comment section below.