我希望能够有一种方法来创建适用于开发和生产的动态 URL。现在我正在构建这样的 URL:
header("Location: http://".$_SERVER["HTTP_HOST"]."/contact.php?failed");
但问题是我目前在我的 WAMP 服务器上运行这样的网站:
http://localhost/vdname/contact.php
因此该行代码不会在开发中生成正确的 URL - 它构建:
http://localhost/contact.php?failed
相反,因此我得到了预期的404
. 如何正确构建 URL,以便它们在开发和生产中都可以使用?
编辑
根据许多建议,最好利用文件VirtualHost
中的条目来httpd.conf
实现这一点,这样我就可以在本地使用普通域名。所以,我试图让它工作,但它并没有像我想要的那样工作,请考虑来自 conf 的这段代码:
#Listen 12.34.56.78:80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/example
ServerName local.example.com
</VirtualHost>
以及相关的hosts
文件配置:
127.0.0.1 local.example.com
但是当我导航到时,http://local.example.com/contact.php
我得到了403 Forbidden
,当我运行时,nslookup local.example.com
我也没有得到127.0.0.1
。