环境windows7,wampserver集成环境,thinkphp5.0文件wamp目录:D:/wamp/wwwthinkphp目录:F:/tp5thinkphp入口文件:F:/tp5/public/index.php第一步:修改http.conf文件,包含http-vhosts.conf配置文件。点击wamp-apache-http.conf,用记事本打开,找到这里。#Virtualhosts#Includeconf/extra/httpd-vhosts.conf改为#VirtualhostsIncludeconf/extra/httpd-vhosts.conf注意:不要去掉第一个#号,否则wamp无法正常运行第二步:配置http-vhosts.conf点击wamp-apache-http-vhosts.conf,用记事本打开,全选,粘贴以下内容。#VirtualHost示例:#几乎所有Apache指令都可以进入VirtualHost容器。#第一个VirtualHost部分用于不匹配任何块中的ServerName或ServerAlias的所有请求。#ServerAdminwebmaster@dummy-host.example.comDocumentRoot"D:\wamp\www"ServerNamelocalhostServerAliaswww.dummy-host.example.comErrorLog"logs/localhost-error.log"CustomLog"logs/localhost-access.log"commonServerAdminwebmaster@dummy-host2.example.comDocumentRoot"F:\tp5\public"ServerNametp5.comErrorLog"logs/tp5.com-error.log"CustomLog"logs/tp5.com-access.log"commonRequireallgranted在第一个例子中只修改了servername和documentRoot,这样的配置保证了我们打开vhost后仍然可以访问到www目录。第二个例子,除了修改serverName和documentRoot外,还增加了Directory这句话。如果不加这句话,访问tp5.com时会报403权限错误。注意:DocumentRoot"F:\tp5\public"#填写入口文件所在文件夹ServerNametp5.com#使用tp5.com访问网站入口文件第三步:修改C:\Windows\System32\drivers\etc\在hosts文件的最后一行添加127.0.0.1tp5.com,最后重启wamp,在浏览器中输入tp5.com,看到这样的页面就成功了:)一键操作点击在wamp主页的工具栏下添加虚拟主机,可以帮你一键添加虚拟主机,但是当你访问wamp主页时,页面出现如下警告(原因暂不清楚):numberofdoesnotmatchthenumberofServerNameind:/wamp/bin/apache/apache2.4.23/conf/extra/httpd-vhosts.conffileThenumberof