![Chrome 将本地 VirtualHost 域名路由到 Google 搜索](https://linux22.com/image/1347287/Chrome%20%E5%B0%86%E6%9C%AC%E5%9C%B0%20VirtualHost%20%E5%9F%9F%E5%90%8D%E8%B7%AF%E7%94%B1%E5%88%B0%20Google%20%E6%90%9C%E7%B4%A2.png)
我使用 Xampp 为我提供一个本地主机环境来测试 PHP。我最近在 xampp 的 httpd-vhosts.conf 文件中设置了一个虚拟主机,这样我就可以将项目分离到它们自己的域名空间中 - 我的虚拟主机描述如下:
NameVirtualHost *
<VirtualHost *>
DocumentRoot "C:\xampp\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\xampp\xampp\htdocs\sales_dev2"
ServerName sales.dev
<Directory "C:\xampp\xampp\htdocs\sales_dev2">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\xampp\xampp\htdocs\opencart"
ServerName opencart.local
<Directory "C:\xampp\xampp\htdocs\opencart">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
我还编辑了我的主机文件,以便每个描述的 ServerName 都能解析为 127.0.0.1。
此设置在 FireFox 和 IE 中运行良好,但在 Chrome 中,不遵循可识别 TLD 的 ServerName 会解析为对该字符串的谷歌搜索(例如谷歌搜索“opencart.local”)
有人可以指教如何解决这个问题吗?
答案1
.dev 附带了许多令人不悦的包袱,比如 Chrome 要求你使用 https,即使你的应用程序实际上并不需要它。最好使用诸如 .localhost 之类的适当解决方案。
这RFC 状态这:
为了安全地满足这些需求,我们保留了四个域名,如下
所列并所述。.test .example .invalid .localhost ".test" is recommended for use in testing of current or new DNS related code. ".example" is recommended for use in documentation or as examples. ".invalid" is intended for use in online construction of domain names that are sure to be invalid and which it is obvious at a glance are invalid. The ".localhost" TLD has traditionally been statically defined in host DNS implementations as having an A record pointing to the loop back IP address and is reserved for such use. Any other use would conflict with widely deployed code which assumes this use.
答案2
您可以在 Vhost 名称末尾输入 .dev。它将被解决并且 google 永远不会搜索任何内容。
并在主机文件中输入以下 ip。(可能有效,不确定) ::1 yourvhost