How to Set up a permanent 301 redirect using PHP

PHP 301 Redirect Permanently is used for diverting visitors from one page to other page or different sites. This is helpful for that page which you need to expel from your site 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 use following code in php script.

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.other-website.com");
?>

On same domain if you want to redirect users from old.php to new.php, Edit old.php and put following code at top of file:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://mydomain.com/new.php");
?>