PHP with 301 redirect root domain to www domain name

Source: Internet
Author: User

PHP Implementation 301 Permanent Redirect the domain name without www to the domain name with www, that is, redirect to

If you only need to complete this function, the PHP code can be written like this:

1<?PHP2 $the _host=$_server[' Http_host '];//get access to the domain name you entered3 $request _url=isset($_server[' Request_uri '])?$_server[' Request_uri ']: ';//determine the back part of the address4 if($the _host!== ' ')//This is the address of my previous domain name5{Header(' http/1.1 301 Moved permanently ');//Issue 301 Head6 Header(' location: '.$request _url);//jump to my new domain address7 } 8?>

PHP with 301 redirect root domain to www domain name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.