The code for PHP to implement 301 redirect is as follows:
Header('HTTP/1.1 301 Moved Permanently');//Send 301 header
Header('Location: http://www.'.$strDomain.$request_uri);//Jump to my new domain name address
I wrote the 301 code using the 301.inc.php file and quoted it in the headers of other files
//----------------------------------
//301 Redirect
$strDomain="chinawecan.com";
$the_host = $_SERVER['HTTP_HOST']; //Get the domain name entered
$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';//Judge the back part of the address
if($the_host !== 'www.'.$strDomain) //This is the previous domain name I want
{
/* "!==" means not exactly equal. You can also use "!=" not equal. In this way, you can replace the previous domain name with
Including gcxirang.com, www.gcxirang.com and the new domain name gcidc.net are all redirected to www.gcidc.net*/
Header('HTTP/1.1 301 Moved Permanently');//Send 301 header
Header('Location: http://www.'.$strDomain.$request_uri);//Jump to my new domain name address
}
//----------------------------------
?>
Quote as follows:
//----------------------------------
//301 Redirect
include('include/301.inc.php');
?>