“Error 404 – Page Not Found” – Is one of the most common web errors people encounter day-to-day in browsing or surfing the Internet.
We know that error pages offer an obviously negative user experience and also have a bad impact on search engines. 404 pages are bad for SEO and can realy get search engines penalize your website(s) if at all your pages or articles lead to too many 404 status error code pages.
When coding a one page site, you might not have the time to create a custom 404 page. In which case, you might as well redirect the 404 page to your site’s homepage. In this article, we will show you how to redirect 404 page to home page in WordPress or redirect 404 error page to a custom page.
All you have to do is open your 404.php file in your theme’s folder. If it doesn’t exist, then create a blank php file. Paste the following code in there:
1 |
<?php |
2 |
header( "HTTP/1.1 301 Moved Permanently" ); |
3 |
header( "Location: " .get_bloginfo( 'url' )); |
4 |
exit (); |
5 |
?> |
That’s all. Now when a user hits a 404 page will be redirected to the homepage.
Note: This should be used in very specific cases. In most other cases (i.e blogs, portfolios etc)
How to Redirect 404 Page to a Custom Page in WordPress
“If you don’t have a 404.php INSIDE your theme folder – WP displays the main (index) page when page not found, without you messing with the htaccess.”
Not for me.
I have put this code into a file named 404.php :
<?php
header("Status: 301 Moved Permanently");
header("Location:http://www.yourdomain.com/custom-page");
?>
(replace: http://www.yourdomain.com/custom-page
) with your custom URL to redirect to.
All the best, to me it worlks pretty cool! Your views.
WhatsApp: +254 711552531 or Leave a comment below.