Rules for binding two-level domain names to subdirectories via htaccess

Source: Internet
Author: User

Many domestic virtual host business is very stingy, generally a host only provides 1 domain name binding, and does not support multiple subdomains. At this point we can set the redirection by using the. htaccess file to bind the level two domain name to the specified subdirectory.
First to bind to the domain name a record or CNAME also point to the host IP and the main domain name, and then can. htaccess bind the appropriate folder by using the following code:

The code is as follows Copy Code


Rewriteengine on

Rewritecond%{http_host} ^bbs.domain.com$

Rewritecond%{request_uri}!^/bbs/

Rewritecond%{request_filename}!-f

Rewritecond%{request_filename}!-d

Rewriterule ^ (. *) $/bbs/$1

Rewritecond%{http_host} ^bbs.domain.com$

Rewriterule ^ (/) $ bbs/index.php [L]

If many of the two-level domain names are specified, each is written like this. htaccess files can be very large and bloated, using the following regular matching notation:

The code is as follows Copy Code


Rewritecond%{http_host} ^ (bbs|blog|download). domain.com$
Rewriterule ^ (. *) $/%1/$1 [L, NC]

In this way, will automatically the BBS corresponding to the BBS directory, blog corresponding to the blog directory, download corresponding to the download, to add a new domain name, only to be added in the above line in the format.

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.