PHP implements 301 permanent redirection with complete parameter code. PHP implements 301 permanent redirection and points the domain name without www to the domain name with www. the implementation method is obtained. That is, veryhuo.com is redirected to www.veryhuo.com. if you only need to complete this function, php code PHP will implement 301 permanent redirection and direct the domain name without www to the domain name with www.
That is, bkjia.com is redirected to www.bkjia.com. if you only need to complete this function, the php code can be written as follows:
Copy to ClipboardReference: [www.bkjia.com] Header ("HTTP/1.1 301 Moved Permanently ");
Header ("Location: http://www.bkjia.com ");
?>
However, visitors may include subdirectories or specific files behind the website, such as bkjia.com/wap.php.
This requires processing the sub-path after the root domain name. The following code will process the sub-path after the root domain name as a parameter, and redirect to the complete address with www through 301.
Copy to ClipboardReference: [www.bkjia.com] $ The_host = $ _ SERVER ['http _ host']; // Obtain the entered domain name
$ Request_url = isset ($ _ SERVER ['request _ url'])? $ _ SERVER ['request _ url']: ''; // judge the part after the address
If ($ the_host! = 'Www .bkjia.com ') // This is the address of the previous domain name.
{Header ('http/1.1 301 Moved Permanently '); // issue the 301 header
Header ('Location: http://www.bkjia.com '. $ request_url); // jump to my new domain address
}
?>
If you ping a domain name without or without www, you will find that the two domain names direct to different ip addresses, but the two domain names access the same website.
Bytes. That is, veryhuo.com is redirected to www.veryhuo.com. if you only need to complete this function, php code...