Configuration Apache two domain windows

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Today Xiaobian to related configuration you a summary of windows Apache two domain names.  

Using the.Htaccess domain name will be bound to the sub directory

The use of local 127.0.0.1 test

Here we take www.jobs.com as an example, the following code in the jobs.com can replace your own domain name here just to test.

Our goal is, different sub domain can access different directory sites:

www.jobs.com => / ;

jobs.com => / ;

news.jobs.com => /news;


1,  Open the Apache mod_rewrite function (is sure to make it support rewriting) to find   in httpd.conf; mod_rewrite put in front of the #, went on the line,

Then open the Apache virtual host   found   in httpd.conf; Virtual hosts in front of the # to go.


2,Add a few domain name, in   C:\WINDOWS\system32\drivers\etc directory to find the file hosts Notepad to open it, add the following three domain names

127.0.0.1          www.jobs.com
127.0.0.1          jobs.com
127.0.0.1          news.jobs.com


3,Fill in the relevant code in the virtual host to make it has access to WWW directory, find the Apache2\conf\extra directory of the   the httpd-vhosts.conf file and opens the code as follows

<VirtualHost *:80>
   DocumentRoot "E:/www"  // Here is the list of items
   ServerName localhost       //Your IP or your domain name
  <Directory "E:/www">    // Here is the list of items
            Options Indexes FollowSymLinks
            AllowOverride all
           Order Deny,Allow
           Deny from all
           Allow from 127.0.0.1   
   </Directory>
</VirtualHost>


Then the www.jobs.com bound to the jobs project directory add code as follows

<VirtualHost *:80>
   DocumentRoot "E:/www/job"      // Here is the directory where jobs
   ServerName www.jobs.com        // Your IP or your domain name
   ServerAlias *.jobs.com              //Where the use of ServerAlias for multiple domain bound to the same space also is the project directory
   <Directory "E:/www/job">        // Here is the directory where jobs
           Options Indexes FollowSymLinks
           AllowOverride all
           Order Deny,Allow
           Deny from all
           Allow from All
   </Directory>
</VirtualHost>



 Set up and then restart the Apache, if the restart encountered error log Apache boot Baocuo to view the Apache, modified according to demand.


4,The establishment of.Htaccess file in the jobs directory add the following code inside


RewriteEngine on

#Www.jobs.com access to the root directory

RewriteCond %{HTTP_HOST} ^www.jobs.com$
RewriteCond %{REQUEST_URI} !^/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /$1
RewriteCond %{HTTP_HOST} ^www.jobs.com$
RewriteRule ^(/)?$ /index.php [L]

#News.jobs.com access to the news directory


RewriteCond %{HTTP_HOST} ^news.jobs.com$
RewriteCond %{REQUEST_URI} !^/news/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /news/$1
RewriteCond %{HTTP_HOST} ^news.jobs.com$
RewriteRule ^(/)?$ news/index.php [L]

I want to bind the news.jobs.com is bound to the new directory, so not only to be placed in the root directory.htaccessFile,

Also placed the.Htaccess file in the new directory, new directory in the.Htaccess written as follows:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
ErrorDocument 403 /404.htm
ErrorDocument 404 /404.htm


All done you can try www.jobs.com job.com   news.jobs.com visit to see the results you want.  

If you need other two level domain name access to it in accordance with the above method to repeat step 2, 4 can be, do not need to restart Apache. 



This involved only in order to test environment used for calibration and for safety, please after all set for products.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Randy at October 23, 2013 - 10:57 PM