1、配置本地路由表(C:\Windows\System32\drivers\etc\hosts)
在文件的末尾加入
127.0.0.1 localhost
127.0.0.1 www.tp5.com
2、apache开启虚拟主机(D:\xampp\apache\conf\httpd.conf)
# Virtual hosts
Include conf/extra/httpd-vhosts.conf//确保此段开头没有#,也就是确保引入了 vhosts 虚拟主机配置文件。
<Directory "D:/xampp/cgi-bin">
AllowOverride All
Options None
Require all granted
</Directory>
//修改为
<Directory "D:/xampp/cgi-bin">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
DocumentRoot "D:/xampp/htdocs"//确保此处路径是你要访问的项目的根路径
3、修改虚拟主机配置(D:\xampp\apache\conf\extra\httpd-vhosts.conf)
<VirtualHost *:80>
DocumentRoot "D:/xampp/htdocs/"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "D:/xampp/htdocs/tp5/public"
ServerName www.tp5.com
</VirtualHost>
4、重启apache