A 404 Not Found Error/Page is generated when a user is able to successfully communicate with the server, but the server is unable to find the requested content. Normally, 404 Not Found errors are generated when a user follows a broken/dead link.
Almost every theme that you use with your self hosted WordPress Blog have an inbuilt 404 Page (404.php), which you can customize as per your site/blog requirements. But, how about 301 Redirecting ALL these 404 Not Found Error Pages to your WordPress Blog Homepage without using/editing .htaccess?
For redirecting all 404 Not Found Error Pages to Homepage in WordPress, simply follow these steps:
1. Login to your WordPress Dashboard and head over to Appearance > Editor. Here you need to find 404.php (HTTP 404 Page Not Found Template) for your current theme:
2. Delete every line of code present in your current 404.php file and enter following lines of code in it:
3. Hit the Update File Button and everything is set!
Important Notes:
Almost every theme that you use with your self hosted WordPress Blog have an inbuilt 404 Page (404.php), which you can customize as per your site/blog requirements. But, how about 301 Redirecting ALL these 404 Not Found Error Pages to your WordPress Blog Homepage without using/editing .htaccess?
301 Redirect ALL 404 Not Found Error Pages to Homepage in WordPress
For redirecting all 404 Not Found Error Pages to Homepage in WordPress, simply follow these steps:
1. Login to your WordPress Dashboard and head over to Appearance > Editor. Here you need to find 404.php (HTTP 404 Page Not Found Template) for your current theme:
2. Delete every line of code present in your current 404.php file and enter following lines of code in it:
<?php
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: “.get_bloginfo(‘url’));
exit();
?>
3. Hit the Update File Button and everything is set!
Important Notes:
- Make sure you backup the code of your current 404.php file before trying/testing the above trick. I have seen many WordPress Themes which have unnecessary complex coding in 404.php file and editing the 404.php file in such theme breaks blog functionality!
- The above lines of Code will 301 Redirect All Users as well as Search Engine Bots to your Blog Homepage [header("Location: ".get_bloginfo('url'));]
- Search Engine Ranking will not be affected in any way, as we are using 301 Permanent Redirection here
- The above trick will actually remove ALL exiting 404 Not Found Errors from Google Webmasters Tools and Bing Webmasters! – Pretty cool! huh!?
- Instead of Homepage, if you want to redirect ALL 404 error pages to some other URL, check out THIS POST
No comments:
Post a Comment