"Uncle Tao's unique building techniques" use the. htaccess file to implement the sub-domain mapping level two directory

Source: Internet
Author: User

Many webmasters want to base on the main domain name, to establish a number of subdomains, such as the main domain name is www.abc.com, want to add bbs.abc.com or blog.abc.com, let the sub-domain to the space of a certain level two directory such as bbs.abc.com corresponding Www.abc.com/bbs, is this a technique you want to learn? Some advanced virtual space and VPS can be configured through the background to achieve, for small space This How to break it? Listen to Uncle Tao to tell you ~

First step: space-bound sub-domain

In the space background, the binding domain name of the panel, you want to add the sub-domain name, such as Bbs.abc.com

Step Two: Domain name resolution:

To the domain manager of the background, your sub-domain name, as a CNAME or a record, resolved to the same as the primary domain address (a record corresponds to an IP address, the CNAME corresponds to a URL)

Step three: Add or modify the. htaccess file (for Linux hosts only, the Windows Host configuration method comes back separately)

In the. htaccess file, add the following nodes and modify them as you like.

# Open function

Rewriteengine on

#先作一个301, the domain name without www, go to the domain name with www (this must be written in front, otherwise it will be covered by the following sub-domain rules)

Rewritecond%{http_host} ^abc.com$

Rewriterule ^ (. *) $ http://www.abc.com/$1 [r=301,l]

#子域名设置正式开始

#把abc. com to your domain name, change BBS into your subdomain, and replace bbs/with your level two directory.

Rewritecond%{http_host} ^ (bbs.)? abc.com$

Rewritecond%{request_uri}!^/bbs/

Rewritecond%{request_filename}!-f

Rewritecond%{request_filename}!-d

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

Rewritecond%{http_host} ^ (bbs.)? abc.com$

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

#子域名设置结束

After writing, upload the. htaccess file to the root of the Web site.

If you support Uncle Tao, Welcome to join Uncle Tao's game VIP Exchange Group Oh ~ ~

Translated from "Uncle Tao Blog": http://game.jiuyuango.com/post/14.html

"Uncle Tao's unique building techniques" use the. htaccess file to implement the sub-domain mapping level two directory

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.