Today we introduce this approach, only need to simply modify the httpd-vhosts.conf file, with the. htaccess file can be configured to automatically configure level two domain names. Here we take wpchina.com as an example, the following code in the wpchina.com can be replaced by you want the domain name. Our goal is that different subdomains can access sites in different directories:
wpchina.com =/; home.wpchina.com =/home;bbs.wpchina.com =/bbs;
The first step is to confirm that the Apache server is installed and support the. htaccess module (need to turn on mod_rewrite). You can refer to here or here, or download xampp directly, which is supported by default. The second step is to set the two level domain name. Advanced point can be set in the router, such as the DD-WRT router support domain name Pan-resolution, it will be very convenient. Simply, modify the hosts file directly. Open the C:\Windows\System32\drivers\etc\hosts file, and at the end, add the following three lines of code and save. Win7/
127.0.0.1 wpchina.com127.0.0.1 home.wpchina.com127.0.0.1 bbs.wpchina.com
The third step, in httpd-* : # code signed # Follow the example below, adding the following code:
<virtualhost *:80> documentroot "/xampp/htdocs/www/wpchina.com" ServerName wpchina.com Serveralias *.wpchina.com</virtualhost>
/xampp/htdocs/www/
rewriteengine on# let www.wpchina.com access the root directory Cmsrewritecond%{http_host} ^ Www.wpchina.com$rewritecond%{request_uri}!^/rewritecond%{request_filename}!-frewritecond%{REQUEST_FILENAME}!- Drewriterule ^ (. *) $/$1rewritecond%{http_host} ^www.wpchina.com$rewriterule ^ (/)? $/index.php [L] #让home. wpchina.com Visit home directory Rewritecond%{http_host} ^home.wpchina.com$rewritecond%{request_uri}!^/home/rewritecond%{REQUEST_ FILENAME}!-frewritecond%{request_filename}!-drewriterule ^ (. *) $/home/$1rewritecond%{http_host} ^home.wpchina.com $RewriteRule ^ (/)? $ home/index.php [L] #让bbs. wpchina.com Access BBS directory Rewritecond%{http_host} ^bbs.wpchina.com$rewritecond %{request_uri}!^/wap/rewritecond%{request_filename}!-frewritecond%{request_filename}!-dRewriteRule ^ (. *) $/bbs/$ 1RewriteCond%{http_host} ^bbs.wpchina.com$rewriterule ^ (/)? $ bbs/index.php [L]
/xampp/htdocs/www/
<?phpecho $_server[' script_filename '];? >
At this time, you can try, respectively access wpchina.com, home.wpchina.com, bbs.wpchina.com, you can see different access results. According to the above method, if you want to add another subdomain, just repeat the second and fourth steps, no longer need to restart Apache, affecting other sites. Note: This article refers to the method of configuring subdomains, only for the test environment, not security testing, do not use directly in the production environment.
Reproduced in http://wpchina.org
Automatic configuration of Level two sub-domain names under Windows Apache Server