Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Programming»PHP»301 Permanent Redirect in PHP

    301 Permanent Redirect in PHP

    By RahulFebruary 3, 20232 Mins Read

    When you need to move a page from one location to another, it’s important to redirect users from the old location to the new location. This is where a 301 redirect comes in handy. A 301 redirect is a permanent redirect, which tells search engines that the old page has been moved to a new location permanently and the search engines should update their index to reflect this change.

    Advertisement

    In this article, we’ll show you how to implement a permanent redirect (301) in PHP.

    1. Edit the PHP file: The first step to implement a 301 redirect in PHP is to edit the PHP file. Open the PHP file that you want to redirect in a text editor, such as Notepad or Sublime Text.
    2. Add the header function: Add the following code to the top of the PHP file:

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

      Make sure to replace “http://www.example.com/new-page.php” with the new location of your page.

    3. Save the PHP file: Once you have added the code, save the PHP file and upload it to the server.
    4. Test the redirect: After uploading the PHP file, test the redirect by visiting the old location of your page in your web browser. If the redirect is working, you should be automatically redirected to the new location of your page.

    Conclusion

    In this article, we have shown you how to implement a permanent redirect (301) in PHP. By using a 301 redirect, you can ensure that your users are always directed to the correct location of your page, and that search engines are updated with the correct location.

    HTTP 301 PHP
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Schedule a Cron Job for PHP: A Step-by-Step Guide

    How to Compare Two Array Values in PHP: A Practical Guide

    How to Set Up Apache, MySQL, and PHP on macOS: A Comprehensive Guide

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Setting Up Angular on Ubuntu: Step-by-Step Guide
    • Converting UTC Date and Time to Local Time in Linux
    • Git Restore: Functionality and Practical Examples
    • Git Switch: Functionality and Practical Examples
    • Git Switch vs. Checkout: A Detailed Comparison with Examples
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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