,

PHP:How to do 301 redirect correctly

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Status: 301 Moved Permanently");
$_SERVER['REDIRECT_STATUS'] = 301;
header ("Location: http://www.new-domain.com/location");
exit;
?>

Steps to perform 301 Redirects

  1. Set 2 types of headers to cover all web robots
  2. Set a server variable that won't be seen by any robots but helps the server to do what you want
  3. Redirect
  4. Remember to exit the script, it could make the difference with old versions of the PHP
  5. Also: make sure there are no spaces or strings being printed before this code, a header error might occur