404 pages are mostly ignored by webmasters. But, on the contrary, these pages should not be ignored and they should be used to redirect your visitors to the right page. Here’s a short tutorial on how you can redirect your 404 page visitors to home page or any other page in WordPress.

Sometimes when coding a theme/website, developers may don’t have much time to design and create the 404 page. Or you may simply want to redirect 404 page visitors to any custom or specially designed page of your website. Use the below code to redirect the 404 page to your site’s home page or any other page of your choice.

If you already have a 404.php file in your theme’s root folder, then you will need to remove all its code and paste the below code. And if you don’t have any 404.php, then create a blank 404.php file and add below code in it.

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('URL'));
exit();
?>

Replace the URL part to your home page or any other page of your choice, where you want to redirect your visitors to.

That’s all you need to do. Now whenever a user stumbles upon a 404 page, the page will redirect your user to the home page or any page of your choice.

Note: Before editing 404.php, we would always recommend you to backup your original file.

2 thoughts on “Redirect your 404 Page to Homepage or Any Other Page in WordPress”
  1. Hi Saqib

    I don’t know much about 404 error pages because I had started my blogging career recently.

    But somewhere I read that If any blogger or writer deleted the existing web page then the URL of that web page becomes 404 URL and that page becomes 404 page.

    It is also said that Google don’t like 404 page so I checked my site whether I had any 404 page or not then I found few of the 404 error pages on my site also.

    But Now after reading this post, I can easily handle these pages.

    Thanks for sharing such a helpful post with us. 😀

  2. Very informative post, Saqib. I loved especially how you explained the method to redirect 404 pages to homepage in WordPress. I never tried this method. Thanks for telling me about it.

Leave a Reply

Your email address will not be published. Required fields are marked *