Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»CMS»WordPress»WordPress Redirecting 404 Error to Home Page

    WordPress Redirecting 404 Error to Home Page

    By RahulFebruary 16, 20221 Min Read

    The 404 error means the requested page doesn’t exist on the server. If you are getting multiple 404 errors on your WordPress site and you don’t have any specific page for 404. In this case, you can simply make 301 redirect all 404 requests to your website home page. To do this you don’t need to install the extra plugin on your site, A small PHP code will do this for you.

    Advertisement
    • Top 10 Ways To Boost Your WordPress Website Speed

    Redirect 404 Error Pages to Home

    Got to your WordPress theme directory and edit 404.php file in your WordPress. Let’s add following small PHP script at top of the file. The first line in the script will make the redirection as 301 permanently.

    1
    2
    3
    4
    5
    <?php
      header("HTTP/1.1 301 Moved Permanently");
      header("Location: ".get_bloginfo('url'));
      exit();
    ?>

    Also you can replace .get_bloginfo(‘url’) with your website domain name to avoid extra request to WordPress to get domain name and make redirection more faster like below.

    1
    2
    3
    4
    5
    <?php
      header("HTTP/1.1 301 Moved Permanently");
      header("Location: http://www.example.com");
      exit();
    ?>

    Finally, test the redirection in your browser window.

    • How to Disable Comments on Attachments in WordPress

    404 WordPress
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    10 Simple Ways to Speed Up Your WordPress Website

    10 Simple Ways to Speed Up Your WordPress Website

    Create A Custom 404 Error Page on Apache

    Create A Custom 404 Error Page on Apache

    Apache 404 Redirect to Homepage

    Apache 404 Redirect to Homepage

    View 8 Comments

    8 Comments

    1. Andy Globe on February 15, 2022 9:39 am

      Does anyone know if the code works as well for multisite installations?

      If so, does the 404 page bounce to the subdomain / subfolder / subsite or the main or root domain / folder / site?

      Reply
    2. Rozaliano on July 27, 2019 3:46 pm

      Great post!

      Reply
    3. vanessa on June 13, 2019 11:51 am

      Thanks :)))))

      Reply
    4. ludogame on April 5, 2019 10:45 am

      Thank you so much for writing up a blog on this topic. Having a 404 pages causes a big problem in terms of ranking, traffic & sales. Specially for E-commerce website. We do have tried “Redirection” plugin and it works perfectly fine and easy to use. Once again thanks for sharing the blog..!!

      Keep up the good work.

      Reply
    5. Udit Khanna on December 14, 2018 7:29 am

      Thanks for sharing information about 404 error pages.
      404 error comes when requested page not found on the web server. If you are getting multiple 404 errors on your WordPress site and you don’t have any specific page for 404. In this case, you can simply make 301 redirect all 404 requests to your website home page.

      Reply
    6. Satruk on November 22, 2017 7:20 pm

      Its works for my blog, very simple script. Thank you so much!

      Reply
    7. Matias on October 24, 2017 9:56 pm

      Hey brother, well if you do by 404.php I think can send 2 HTTP header codes (404 with 301)

      or with plugin is only 301 immediately: https://wordpress.org/plugins/404-to-homepage-littlebizzy/

      Reply
    8. Geroges on October 3, 2017 11:44 am

      There’s a smarter way would be to redirect to a similar post using a plugin such as WP 404 Auto Redirect to Similar Post. It will use the words in the 404 URL to match against already existing pages.

      A must have!

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • A Comprehensive Look at the Simple Mail Transfer Protocol (SMTP)
    • Understanding Basic Git Workflow: Add, Commit, Push
    • The Difference Between Git Reset –soft, –mixed, and –hard
    • Understanding the Staging Area in Git’s Workflow
    • Python Function with Parameters, Return and Data Types
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.