: This article mainly introduces the use of php resolution to achieve second-level domain name redirection. For more information about PHP tutorials, see. After registering a domain name, it is often necessary to implement different second-level domain names to access different nodes of the site
Generally, the domain name registrar provides a cname resolution method. you can define a second-level domain name to a different ip address.
For example
Www.abc.com points to master node 1.2.3.4
Bbs.abc.com points to 1.2.3.4/bbs or another ip address.
However, if a website is rented a hosted space, the problem also arises.
The website has only one ip address, and the website is a hosted space, not a hosting host. different access nodes cannot be directly set. the hosting space can only be set with one portal website provided by the space provider.
That is, the website has only one portal, and the second-level domain name cannot be directly resolved to different subdirectories.
Php code can solve this problem,
Ideas
1. define different second-level domain names to point to the same website portal
2. in index. php on the first page of the website portal, identify the domain name entered by the user, and redirect to the website subpoint.
The php global variable $ _ SERVER ['http _ host'] can obtain the domain name string currently accessed by the user. in this case, query the strings of each defined sub-domain name, use the header function to redirect to different pages.
The code is as follows:
If (strpos ($ _ SERVER ['http _ host'], "china ")! = False) // be sure to use it! = Unavailable! =; Otherwise, false and 0 cannot be distinguished.
{//
Header ('Location:/china/indexphp ');
} Elseif (strpos ($ _ SERVER ['http _ host'], "bbs ")! = False)
{
Header ('Location:/bbs/forum. php ');
}
Else
{// Display the home page
Header ('Location:/templets/default/index.htm ');
}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above introduces the use of php resolution to achieve second-level domain name redirection, including the content, hope to be helpful to friends interested in PHP tutorials.