1、找到C:WindowsSystem32driversetc下的hosts文件,在文件最后增加以下内容:
127.0.0.1 mysite.net
需要注意的是,此hosts文件可能会不让保存,解决的方法是将此hosts文件拷贝至其它位置(比如桌面),修改完毕后拷贝回来,将原文件覆盖即可。
2、打开Apache的配置文件httpd.conf,找到Include conf/extra/httpd-vhosts.conf这行,如果这一句前面有#的话,将其去掉。
3、打开Apache中confextra下的httpd-vhosts.conf文件,在最后写入:
(1)PHP2.2下
NameVirtualHost *:80 <VirtualHost *:80> ServerName mysite.net DocumentRoot "D:xampphtdocsmysite" <Directory "D:xampphtdocsmysite"> Options FollowSymLinks IncludesNOEXEC Indexes DirectoryIndex index.html index.htm index.shtml default.html default.htm index.php default.php AllowOverride All Order Deny,Allow Deny from All Allow from 127.0.0.1 </Directory> </VirtualHost>
(2)PHP2.4下
<VirtualHost 127.0.0.1:80> ServerName mysite.net DocumentRoot "D:xampphtdocsmysite" <Directory "D:xampphtdocsmysite"> Options FollowSymLinks IncludesNOEXEC Indexes DirectoryIndex index.html index.htm index.shtml default.html default.htm index.php default.php AllowOverride All Require all denied Require ip 127.0.0.1 ::1 Require local </Directory> </VirtualHost>
4、重启Apache,浏览器中输入mysite.net就可以访问D:xampphtdocsmysite这个项目了。
注意:将上文中红色颜色部分的内容更换为你想要使用的虚拟域名,蓝色部分更换为对应项目存储的路径。