本地主机、子域名、使用XAMPP

4

我是一名网站开发者,经常需要在本地机器上查看不同的项目。目前我的localhost被设置为"C:/xampp/htdocs/"。我想创建一个"company.localhost",它指向"C:/xampp/htdocs/company/"。

我已经编辑了c:\windows\system32\drivers\etc\hosts文件,在其中添加了以下行:

127.0.0.1 company.localhost

我已经编辑了c:\xampp\apache\conf\extra\httpd-vhosts.conf文件,以便包含以下内容:

<VirtualHost *:80>
    ServerName company.localhost
    ServerAlias company.localhost
    DocumentRoot "C:/xampp/htdocs/company/"
    DirectoryIndex index.php index.html index.htm index.shtml
</VirtualHost>

当我在Chrome浏览器中访问http://company.localhost时,它显示本地主页。我已启动并重新启动了Apache服务器。如何在浏览器中访问company.localhost/index.php?
我的操作系统是Windows 7。
编辑:现在,http://localhosthttp://company.localhost都指向了company.localhost的主页。如何恢复我的常规localhost主页并仍然保留company.localhost的正确主页?
谢谢。

也许这会有所帮助,在Windows中使用\而不是/。 - lmarcelocc
我一直在复制vhosts文件中的示例,但我会尝试一下。编辑:现在它告诉我网页不可用。 - ShiningLight
使用反斜杠而不是正斜杠导致了一个错误,使得Apache突然停止。 - ShiningLight
1
抱歉,我不是Apache的大师。但这很奇怪,我正在使用Windows和XAMPP,并使用那个斜杠。让我们等待有人来帮助你 :) - lmarcelocc
1个回答

0

当在同一端口上创建多个虚拟主机时,必须指定每个主机名。否则,您只有一个绑定到端口80的站点,并且所有本地主机调用都将指向您指定的文件夹。

这是缺失的代码,在c:\xampp\apache\conf\extra\httpd-vhosts.conf中类似代码之前或之后添加即可。

<VirtualHost *:80>
    ServerName localhost
    ServerAlias localhost
    DocumentRoot "C:/xampp/htdocs/"
    DirectoryIndex index.php index.html index.htm index.shtml
</VirtualHost>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接