Second-level domain name redirection using php resolution

Source: Internet
Author: User
: 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.

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: info-contact@alibabacloud.com 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.