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.