Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Programming»PHP»How To Permanent Redirect (301) a Page in PHP

    How To Permanent Redirect (301) a Page in PHP

    RahulBy RahulMarch 14, 20151 Min ReadUpdated:June 8, 2021

    PHP 301 Redirect Permanently is used for redirecting user from one page to other page or other websites. This is useful for that page which you want to remove from your website and put new pages or replacing old domain with new domain. With the 301 permanent redirect search engines indexes new url or domain and removed old from their indexing.

    To redirect users to other domain put following code in php script.

    PHP
    1
    2
    3
    4
    5
    6
    <?php
      // Permanent 301 redirection
      header("HTTP/1.1 301 Moved Permanently");
      header("Location: http://www.other-website.com");
      exit();
    ?>

    PHP
    1
    2
    3
    4
    <?php
    header("Location: https://www.systutorials.com/", true, 301);
    exit();
    ?>

    You can also apply a permanent 301 redirect between webpages for the same domain. Using the following PHP script to redirect users from old.php to new.php within the same domain. Edit your old.php and put following code at top of file.

    PHP
    1
    2
    3
    4
    5
    <?php
      // Permanent 301 redirection to same domain
      header("HTTP/1.1 301 Moved Permanently");
      header("Location: http://mydomain.com/new.php");
    ?>

    HTTP 301 PHP
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Reset Admin Password on Ubuntu
    Next Article How To Edit Hosts File on Your System

    Related Posts

    How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04

    Updated:May 9, 20223 Mins Read

    How To Install Linux, Nginx, MySQL, & PHP (LEMP Stack) on Ubuntu 22.04

    Updated:April 7, 20227 Mins Read

    How To Install LAMP Stack on Ubuntu 22.04 LTS

    Updated:April 20, 20225 Mins Read

    How To Setup Apache, PHP & MongoDB in Ubuntu & Debian

    Updated:October 8, 20213 Mins Read

    How To Install and Use PHP Composer on Debian 11

    Updated:February 16, 20224 Mins Read

    How To Install PHP (8.1, 7.4 & 5.6) on Debian 11

    Updated:February 16, 20224 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    • (Resolved) Please install all available updates for your release before upgrading
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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