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 .
- <ifmodule mod_rewrite. C>
- Rewriteengine on
- Rewritebase/
- # bind music.xmgho.com to subdirectory music
- Rewritecond%{http_host} ^music\.xmgho\.com$ [NC]
- Rewritecond%{request_uri}!^/music/
- Rewriterule ^ (. *) $ music/$1? Rewrite [L,QSA]
- #可以绑定多个 just repeat the last three lines of code and change the domain name, directory name just fine
- </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:
- <ifmodule mod_rewrite. C>
- Rewriteengine on
- Rewritebase/
- #只许绑定的域名访问
- Rewritecond%{http_host}!^music\.xmgho\.com$ [NC]
- Rewriterule (. *) http://music.xmgho.com/$1 [l,r=301]
- #对绑定目录下与 Processing of directories with the same name
- Rewritecond%{request_uri} ^\/music\/[NC]
- Rewritecond%{query_string}!^ (. *)? Rewrite
- Rewriterule ^ (. *) $/%{request_uri}/%{request_uri}/$1? Rewrite [L,QSA]
- </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)