PHP Redirect with HTTP 301

The htaccess method can be found in How to Redirect Old Domain to New Domain Using htaccess Redirect.

This is the method that use php to generate the HTTP 301 Redirect.

There are a lot of benefits of using HTTP 301 Redirect. These benefits can be found in the htaccess method post.

The header(“HTTP/1.1 301”) part must be used before the location part, otherwise PHP will automatically set the status code to HTTP/1.1 302 Found.

The code:

<?php
// Permanent 301 redirection
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.fclose.com/");
exit();
?>

Eric Zhiqiang Ma

Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *