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