How to redirect 404 error page to homepage in WordPress?
If you want to Redirect 404 page to homepage: first Install and activate a Redirection plugin to do this one-by-one operation.
To install a redirection plugin:
- Log in to the WordPress admin dashboard, select the Add Plugins page and search for redirection
- Click Install and activate the plugin
- Return to settings on the dashboard to enable the plugin
- In Tools > Redirection > Add new redirection
- In the Source URL box, type or paste the broken/old URL
- In the Target URL box, type or paste the new URL
- Opt for URL and referrer in the match drop down
- In the Action box, chose Redirect to URL
- Click on Add Redirection
If there are many pages showing the 404 error on your website then the best thing to redirect them all to homepage rather other than lose your traffic.
Manually Redirect via a redirection plugin
Redirecting your 404 not found pages to your website’s home page can help reduce bounce rate and give your users a chance to discover other useful content on your website.
First, you’ll need to create a new file in your WordPress theme folder and name it 404.php
. If your theme already has a 404.php
file, then you’ll need to edit that file instead.
To edit this file, you need to go to your hosting account with an FTP client or their file manager tool.
Once you go to file manager to your website, you will be able to see your 404.php
file in your WordPress themes folder.
You need to add the following code as the first line in your 404.php
file:
1
2
3
4
5
|
<?php header( "HTTP/1.1 301 Moved Permanently" ); header( "Location: " .get_bloginfo( 'url' )); exit (); ?> |
save the 404.php
file, when a page is not found, instead of showing a 404 page, they will be redirected to your website homepage.
Pros of redirect 404 pages to homepage
- Users can disappointed when they find a 404 error page. To keep traffic, you can redirect to the homepage.
- If your website has too many 404 errors, it’s best to redirect users to the homepage can help reduce bounce rate and give your users a chance to discover other useful content on your website.
- If you change the title of article URL of an old blog post will get a 404 message and nobody will ever read the article.
Cons of redirect 404 pages to homepage
- Redirecting all pages to your homepage can be confusing for users if they are trying to go to a specific page and keeping land on a homepage.
- Many 404 redirects will create bounce rate your website’s overall search engine rating. However redirecting non-existing URLs to homepage not a good idea for your website users experience.