This article is to share the content of the use of PHP to achieve two-level domain name redirection, the need for friends can refer to the content of the article
After registering the domain name, often need to implement different two level domain name to visit different nodes of the site
The General domain registrar provides a way to parse the CNAME, you can define the two-level domain name to different IP.
Like what
Www.abc.com pointing to the primary node 1.2.3.4
Bbs.abc.com point to 1.2.3.4/bbs or another IP
But if the site rented a hosting space, the problem of egg pain came.
The site has only one IP, and the site is a rented hosting space, not a managed host, not directly set up different access nodes, the managed space can only set a space provider to provide a portal URL
That is, the site has only one entry, two-level domain name can not be directly resolved to different sub-directories
Using PHP's code can solve this problem,
Ideas
1. Define different level two domain names and point to the same site portal
2. On the first page of the portal index.php, determine the domain name entered by the user and redirect to the site sub-contact
PHP global variable $_server[' http_host '], you can obtain the user's current access to the domain name string, in this case to query their own defined sub-domain strings, and then use the header function to redirect to different pages
The code is as follows
if (Strpos ($_server[' http_host '), "China")!== false)//Note Be sure to use!== cannot use! =, otherwise you cannot distinguish between false and 0
{//
Header (' location:/china/indexphp ');
}elseif (Strpos ($_server[' http_host '), "BBS")!== false)
{
Header (' location:/bbs/forum.php ');
}
Else
{//Show home page
Header (' location:/templets/default/index.htm ');
}
Related recommendations:
A piece of code that uses PHP to parse JSON data
Parsing RDDL documents with PHP