Using PHP parsing to implement level two domain redirection

Source: Internet
Author: User
Tags hosting

After registering the domain name, often needs to realize different two level domain name to visit the different node of the site

The general domain name registers the organization to provide the CNAME the analytic way, may the two level domain name define to the different IP.

Like what

Www.abc.com point to primary node 1.2.3.4

Bbs.abc.com point to 1.2.3.4/bbs or another IP but if you rent a hosting space, the problem of egg aches is coming.

Web site has only one IP, and the site is rented hosting space, not managed host, can not directly set different access nodes, managed space can only set up a space provider to provide a portal URL

That is, the site has only one portal, the level two domain name can not be directly resolved to different subdirectories


Using PHP's code can solve this problem,

Ideas

1. Define different level two domain name, point to the same website portal

2. In the first page of the portal index.php, judge the user entered the domain name, and then redirect to the site sub-contact


PHP global variable $_server[' http_host ', you can get the user's current access to the domain name string, in which to query their own definition of each child domain name string, and then use the header function to redirect to different pages

The code is as follows

if (Strpos ($_server[' http_host '), "country")!== false)//note!== cannot be used with!=, 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 ');
}

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.