http / php:header:location redirect not reirecting to right domain

时间:2013-06-25 00:12:16

标签: php redirect

我正在新主机上设置现有网站的镜像,以准备切换主机。

镜像正在新主机上的帐户的子域中运行。我也有mysql数据库工作。但是,当php代码尝试使用header:location进行重定向时,它会将查看器发送到旧主机,而不是重定向到新主机上的页面。我不能为我的生活弄清楚这一点,因为我无法在代码中找到提到域本身的任何地方。路径只是相对的。

旧主机域。 mysebsite.com

在上面输入加载index.php.

新镜像站点域。 mywebsite.myaccountname.newhost.com

在上面输入会将您带到正确的目录并加载页面index.php

重定向的设置如下:

header("Location: products.php");

而不是转到新主机上的mywebsite.myaccountname.host.com/products.php,而是转到旧主机上的mywebsite.products.php

注意我确实在新主机mywebsite上命名了我的子域名 - 与当前网站的域名相同,但我看不出这是怎么回事。

感谢您提出任何可能导致此问题的建议。

1 个答案:

答案 0 :(得分:3)

尝试使用:

$server = $_SERVER['SERVER_NAME'];
header("Location: http://$server/products.php");