在虚拟主机设置文件xampp\apache\conf\extra \httpd-vhosts.conf里设置:取消 NameVirtualHost *:80 前面的 ##,这样就启用了 vhosts.conf ,默认的httpd.conf默认配置失效。虚拟主机配置将只设置在httpd-vhosts.conf里。localhost 的目录默认配置记得也按此设置。
#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any block.
#
ServerAdmin postmaster@dummy-host.localhost
DocumentRoot "I:/xampp/htdocs/"
ServerName localhost
ServerAlias localhost
ErrorLog "logs/dummy-host.localhost-error.log"
CustomLog "logs/dummy-host.localhost-access.log" combined
ServerAdmin postmaster@dummy-host1.localhost
DocumentRoot "I:/xampp/htdocs/a"
ServerName www.a.com
ServerAlias www.a.com
ErrorLog "logs/dummy-host1.localhost-error.log"
CustomLog "logs/dummy-host1.localhost-access.log" combined
ServerAdmin postmaster@dummy-host2.localhost
DocumentRoot "I:/xampp/htdocs/b/"
ServerName www.b.com
ServerAlias www.b.com
ErrorLog "logs/dummy-host2.localhost-error.log"
CustomLog "logs/dummy-host2.localhost-access.log" combined
//至此,XAMPP 的虚拟主机设置完毕,现在 访问 localhost 还是原来的 XAMPP 的帮助指南,访问 www.a.com 将指向到绑定的 a 目录,访问 www.b.com 将指向到绑定的 b 目录。