Linux virtual host through the program implementation of the two-level domain binding to subdirectories

Source: Internet
Author: User

The CP console in a virtual host does not support the ability to bind a two-level domain name to a subdirectory, and the user can bind a two-level domain name to a subdirectory through a program implementation.

There are two ways to bind a two-level domain name to a subdirectory:

1. Configure. htaccess, implemented by pseudo-static code. Specific implementation method reference: Http://help.aliyun.com/knowledge_detail/6554929.html?spm=5176.7114037.1996646101.1.SkYPg8&pos=1

Virtual host and Light cloud host implement sub-directory binding function by pseudo-static

WAN Network virtual host, light cloud host does not support through the console cp.hichina.com settings to point the domain name to the site subdirectory. However, this effect can be achieved by setting pseudo-static rules in the. htaccess configuration file:

For example, to implement access bbs.example.com when jumping to the example.com/bbs/directory,

You can create a. htaccess file under the/htdocs folder and write the following code in the. htaccess file

Rewritecond%{http_host} ^bbs.example.com [NC]
Rewriterule ^ (. *) $
http://example.com/bbs/$1 [l,r=301]

Note: The above method is only applicable to Linux hosts

2. Through the PHP program, the following procedures can be implemented:

<?php
Switch ($_server["Http_host"])
{
Case "a.test.cn": Header ("location:a/");
Break
Case "b.test.cn": Header ("location:b/");
Break
Case "c.test.cn": Header ("location:c/");
Break
}
?>

In the example above, the domain name is test.cn and the program means:
Access to the a.test.cn, will jump to htdocs a directory;
Access to the b.test.cn, will jump to htdocs B directory;
Access to the c.test.cn, will jump to htdocs C directory;

When doing a domain name resolution, you need to resolve the a.test.cn,b.test.cn,c.test.cn to the IP address of the virtual host.

Thus the function of the two-level domain name Binding subdirectory is implemented in the program.

Linux virtual host through the program implementation of the two-level domain binding to subdirectories

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.