Question from Seth P.: I have a WordPress blog that has several missing posts that I’ve deleted because they contained outdated information that was either incorrect or no longer relevant.
My blog now has lots of requests going to the 404 error page because those posts no longer exist.
I’d like to redirect all of those requests to my blog’s home page instead of displaying the 404 error page. How can I do that?
Ricks’s Answer: Hi Seth. As you already know, WordPress typically redirects broken links and calls to missing pages or posts on your blog to a special 404 error page (i.e. 404.php).
Some bloggers do redirect their 404 errors to the blog’s home page, but I don’t recommend it for the following reasons:
1 – Many visitors get confused and frustrated when they’re expecting to land on a particular post/page but end up on the home page instead.
2 – Some search engines consider 404 redirects to the home page to be an attempt to manipulate search engine rankings by redirecting the “link juice” of the missing page to the home page.
For these reasons I prefer to either redirect a missing page to an existing post/page with similar relevant content or leave the outdated page in place and simply replace the outdated content with new content that’s both fresh and relevant to the original post.
However, some bloggers do prefer to have all 404 errors redirected to the blog’s home page. If you’re still one of them after reading what I wrote above, here’s a simple and easy way to make it happen:
1 – Rename your theme’s existing 404.php file to something different. You’ll typically find this file in your WordPress blog’s active theme folder:
/wp-content/themes/theme name/
To make things simple you can just rename the file to 404-original.php. That way if you ever decide to revert back to the original 404 error page, you can just delete the new file you’re about to create and rename the original file back to 404.php.
2 – Open Notepad, then copy and paste the following into a new document:
<?php
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: “.get_bloginfo(‘url’));
exit();
?>
3 – Click File>Save As and name the newly created file 404.php.
4 – In the Save as type: dropdown box, select All Files.
5 – Click Save.
6 – Upload your new 404.php file to your blog’s active theme folder, which again is typically found at:
/wp-content/themes/theme name/
That’s all there is to it. From now on all links to pages that don’t exist will be redirected to your blog’s home page instead of the 404 error page.
Bonus tip #1: Read this post to learn how to enable Two-Factor Authentication on your WordPress blog with the Google Authenticator plugin.
Bonus tip #2: Want to make sure you never miss one of my tips? Click here to join my Rick’s Tech Tips Facebook Group!
Want to ask Rick a tech question? Click here and send it in!
If you found this post useful, would you mind helping me out by sharing it? Just click one of the handy social media sharing buttons below.