Home > Article > Backend Development > PHP implements 301 permanent redirection with parameters complete code_PHP tutorial
PHP implements 301 permanent redirection to point the domain name without www to the domain name with www. Here is the implementation method.
That is, bkjia.com redirects to www.bkjia.com. If you only need to complete this function, the php code can be written like this:
Copy to ClipboardQuoted content: [www.bkjia.com]But visitors may bring some subdirectories or specific files after the URL, such as: bkjia.com/wap.php
This requires processing the sub-path after the root domain name. The following code will process the part after the root domain name as a parameter, and also redirect to the complete address with www through 301.
Copy to ClipboardQuoted content: [www.bkjia.com] $the_host = $_SERVER['HTTP_HOST']; //Get the entered domain nameBy pinging domain names without www and with www, friends will find that the two domain names point to different IPs, but the two domain names access the same website.