简体   繁体   English

Localhost,子域名,使用XAMPP

[英]Localhost, subdomain, using XAMPP

I am a web developer and frequently want to view different projects on my local machine. 我是一名Web开发人员,经常想在我的本地计算机上查看不同的项目。 Currently my localhost is set to "C:/xampp/htdocs/". 目前我的localhost设置为“C:/ xampp / htdocs /”。 I would like to create a "company.localhost" that points to "C:/xampp/htdocs/company/". 我想创建一个指向“C:/ xampp / htdocs / company /”的“company.localhost”。

I have edited c:\\windows\\system32\\drivers\\etc\\hosts to include the line 我编辑了c:\\ windows \\ system32 \\ drivers \\ etc \\ hosts以包含该行

127.0.0.1 company.localhost

I have edited c:\\xampp\\apache\\conf\\extra\\httpd-vhosts.conf to include 我编辑了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>

When I navigate to http://company.localhost in my browser (using Chrome), it shows me the localhost index page. 当我在浏览器中导航到http://company.localhost (使用Chrome)时,它会显示localhost索引页面。 I have started and restarted my Apache server. 我已经启动并重新启动了我的Apache服务器。 How do I get to company.localhost/index.php in my browser? 如何在浏览器中访问company.localhost / index.php?

I am on Windows 7. 我在Windows 7上。

EDIT: Now both http://localhost and http://company.localhost are pointing to the index page for company.localhost. 编辑:现在http:// localhosthttp://company.localhost都指向company.localhost的索引页面。 How do I get my normal localhost index back and still keep correct index page for company.localhost? 如何恢复正常的localhost索引,并为company.localhost保留正确的索引页?

Thank you. 谢谢。

When creating more than one virtual host on the same port, you must specify each host name. 在同一端口上创建多个虚拟主机时,必须指定每个主机名。 Otherwise you only have one site bound to port 80, and all localhost calls will direct to the folder you specified. 否则,您只有一个站点绑定到端口80,并且所有localhost调用将指向您指定的文件夹。

Here is the missing code, add just before or after similar code in c:\\xampp\\apache\\conf\\extra\\httpd-vhosts.conf. 这是缺少的代码,在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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM