Automatic configuration of Level two sub-domain names under Windows Apache Server

Source: Internet
Author: User

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

Related Article

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.