1、首先打开apache的配置文件httpd.conf,并去掉#Include conf/extra/httpd-vhosts.conf前面的#,启用虚拟主机功能
2、先把localhost配置好,免得以后访问localhost出现问题,我的wamp项目根目录是D:wampwww。将下面信息添加到apache的apache/conf/extra下的配置文件httpd-vhosts.conf后面即可;
<VirtualHost *:80>
DocumentRoot "D:/wamp/www"
ServerName localhost
<Directory "D:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
3、配置其他项目虚拟主机:比如配置www.zf.com,打开该链接即可直接访问D:/wamp/www/zf/public目录。“DirectoryIndex index.php”的意思是访问该目录默认打开“index.php”文件
<VirtualHost *:80>
DocumentRoot "D:/wamp/www/zf/public"
ServerName www.zf.com
DirectoryIndex index.php
<Directory />
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
4、修改C:WindowsSystem32driversetc下的host文件,用记事本打开,添加 127.0.0.1 www.zf.com ,重启apache即可