Use. htaccess to bind sub-domain names to subdirectories (available with a pro-test network)

Source: Internet
Author: User

http://www.xmgho.com/archives/783.html use. htaccess to bind the domain name to the subdirectory, as long as your space server must support Apache's rewrite function, only in order to use the. htaccess. If your space is Linux server is generally turned on by default. Bind domain Name

Login The domain name Management desk (such as dnspod) to resolve the domain name needed to bind to your space;
Login to the virtual host/space management desk (such as WAN) bound domain name to space;

First build a TXT file locally, copy the following code changes to replace the domain name and directory you want to bind, and upload to the main site and then change to become. htaccess.
The following are theThe music.xmgho.com  music . htaccess code that is bound to the subdirectory as an example .

    1. <ifmodule mod_rewrite. C>
    2. Rewriteengine on
    3. Rewritebase/
    4. # bind music.xmgho.com to subdirectory music
    5. Rewritecond%{http_host} ^music\.xmgho\.com$ [NC]
    6. Rewritecond%{request_uri}!^/music/
    7. Rewriterule ^ (. *) $ music/$1? Rewrite [L,QSA]
    8. #可以绑定多个 just repeat the last three lines of code and change the domain name, directory name just fine
    9. </IfModule>
If you are to complete the above steps
Your subdomain should be accessible, but you'll find that accessing the main domain name + the bound domain name directory on the browser is also accessible, but that's not what we want. The next step is to complete the last one, and add a. htaccess file in each of the bound directories, such as the music directory
The. htaccess code is as follows:
  1. <ifmodule mod_rewrite. C>
  2. Rewriteengine on
  3. Rewritebase/
  4. #只许绑定的域名访问
  5. Rewritecond%{http_host}!^music\.xmgho\.com$ [NC]
  6. Rewriterule (. *) http://music.xmgho.com/$1 [l,r=301]
  7. #对绑定目录下与 Processing of directories with the same name
  8. Rewritecond%{request_uri} ^\/music\/[NC]
  9. Rewritecond%{query_string}!^ (. *)? Rewrite
  10. Rewriterule ^ (. *) $/%{request_uri}/%{request_uri}/$1? Rewrite [L,QSA]
  11. </IfModule>
By completing the above steps, you will be pleasantly surprised to find that you have achieved the desired effect.

Use. htaccess to bind sub-domain names to subdirectories (available with a pro-test network)

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.