Sometimes you need some top-level domain access to access your local projects, this time you need to configure the virtual host, to your directory to bind a domain name, to achieve a multiple-domain binding access. (local words can be easily bound by modifying the Hosts file name such as www.a.com or Localdemo).
Now suppose you have two directories, one exists in/xampp/htdocs/a and the other is in/xampp/htdocs/b.
Now you want to access www.a.com in the local test when the corresponding directory is/xampp/htdocs/a, access www.b.com The corresponding directory is/xampp/htdocs/b. Know that the Apache configuration can be bypassed, because XAMPP is simply integrated with the Apache Environment Integration package, the implementation of multiple domain name is through the configuration Apache implementation.
The following configuration is for the XAMPP Windows 1.7.4 version, but it is also true for other versions of XAMPP.
Download Address: http://www.jb51.net/softs/308.html
1, first modify the C:/windows\system32\drivers\etc directory under the Hosts file, with notepad++ or Notepad open, add:
Copy Code code as follows:
127.0.0.1 www.a.com
127.0.0.1 www.b.com
2, open xampp\apache\conf\httpd.conf file, search "Include conf/extra/httpd-vhosts.conf", ensure that there is no # annotation before, that is to ensure that the introduction of the Vhosts virtual host configuration file.
Httpd-vhosts.conf is turned on, default httpd.conf default configuration is disabled (make sure that the virtual host configuration is also open in httpd-vhosts.conf file, see 3rd), the domain name that accesses this IP will all point to vhosts.conf The first virtual host in. (Note is the first one, see 4th)
3, in the virtual host settings file xampp\apache\conf\extra\httpd-vhosts.conf set:
Remove the # # in front of the namevirtualhost *:80 so that vhosts.conf is enabled and the default httpd.conf default configuration is invalid. The virtual host configuration will only be set in httpd-vhosts.conf.
Copy Code code as follows:
<virtualhost *:80>
documentroot/xampp/htdocs/a
ServerName www.a.com
</VirtualHost>
<virtualhost *:80>
Documentroot/xampp/htdocs/b
ServerName www.b.com
</VirtualHost>
4, after setting up the 3rd, you will find that access to the localhost directly to the set of the path to go, the problem is in the 2nd section. That is, when the vhosts is turned on, the default httpd configuration is invalidated, and the default access points to the first setting in Vhosts. This is when you want to configure the localhost directory to set it back.
Copy Code code as follows:
<virtualhost *:80>
documentroot/xampp/htdocs/
ServerName localhost
</VirtualHost>
At this point, the XAMPP virtual host is set up, now access to localhost or the original XAMPP help guide, access to www.a.com will be directed to the bound a directory, Access Www.b.com will point to the bound B directory.
Example reference:
XAMPP add VirtualHost to support multiple sites
Add the following in the c:\xampp\apache\conf\extra\httpd-vhosts.conf file:
Copy Code code as follows:
Namevirtualhost *:80
<virtualhost *:80>
DocumentRoot "E:/php/wordpress"
ServerName WordPress
</VirtualHost>
The following section must be joined or inaccessible
<directory "E:/php/wordpress" >
Options Indexes followsymlinks Includes execcgi
AllowOverride All
Order Allow,deny
Allow from all
</Directory>
But it's possible to combine the above two paragraphs together.
Copy Code code as follows:
<virtualhost *:80>
DocumentRoot "E:/php/wordpress"
ServerName WordPress
<directory "E:/php/wordpress" >
Options Indexes followsymlinks Includes execcgi
AllowOverride All
Order Allow,deny
Allow from all
</Directory>
</VirtualHost>
(This section will localhost default access settings back, will have to be placed in the back)
Copy Code code as follows:
<virtualhost *:80>
DocumentRoot "d:/xampp/htdocs/"
ServerName localhost
</VirtualHost>
Add the following in the Hosts file in the C:\WINDOWS\system32\drivers\etc directory:
Copy Code code as follows: