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.
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(); ?> |
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.
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"); ?> |