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