PHP code for 301 redirection. PHP code for 301 redirection PHP code for 301 redirection: header (HTTP1.1301MovedPermanently); code for sending a 301 header (Location: www... $ strDomain. $ request PHP code for 301 redirection
The code for PHP to implement 301 redirection is as follows:
Header ('http/1.1 301 Moved Permanently '); // issue the 301 header
Header ('Location: http: // www. '. $ strDomain. $ request_uri); // jump to my new domain name address
I used the 301. inc. php file to write the 301 code, which can be referenced in other file headers.
//-----------------------------------
// Redirect 301
$ StrDomain = "chinawecan.com ";
$ The_host = $ _ SERVER ['http _ host']; // Obtain the entered domain name
$ Request_uri = isset ($ _ SERVER ['request _ URI '])? $ _ SERVER ['request _ URI ']: ''; // judge the part after the address
If ($ the_host! = 'Www. '. $ strDomain) // This is my previous domain name
{
/* "! = "Is not completely equal to the meaning, you can also use"! = "Not equal to, in this way, you can replace the previous domain name,
Including gcxirang.com, www.gcxirang.com, and all my gcidc.net in the new domain name are redirected to www.gcidc.net */
Header ('http/1.1 301 Moved Permanently '); // issue the 301 header
Header ('Location: http: // www. '. $ strDomain. $ request_uri); // jump to my new domain name address
}
//----------------------------------
?>
Reference:
//-----------------------------------
// Redirect 301
Include ('include/301. inc. php ');
?>
The code for PHP to implement 301 redirection is as follows: header ('http/1.1 301 Moved Permanently '); // send the 301 header ('Location: HTTP: // www. '. $ strDomain. $ request...