简体   繁体   English

http / php:header:location重定向未重定向到正确的域

[英]http/php: header:location redirect not redirecting to right domain

I am setting up a mirror of an existing website on a new host in preparation for switching hosts. 我正在新主机上设置现有网站的镜像,以准备切换主机。

The mirror is running on a subdomain of my account on the new host. 镜像在新主机上我的帐户的子域上运行。 I also have the mysql database working. 我也有mysql数据库工作。 However, when the php code attempts a redirect using header:location, instead of redirecting to the page at the new host, it is sending the viewer to the old host. 但是,当php代码尝试使用header:location进行重定向时,而不是重定向到新主机上的页面,而是将查看器发送到旧主机。 I can't for the life of me figure this out because I cannot find anywhere in the code that mentions the domain itself. 我一生无法解决这个问题,因为我找不到代码中提及域本身的任何地方。 Paths are just relative. 路径只是相对的。

Old host domain. 旧的主机域。 mysebsite.com

Typing in above loads index.php. 输入上面的内容即可加载index.php.

New mirror site domain. 新的镜像站点域。 mywebsite.myaccountname.newhost.com

Typing in above takes you to the right directory and loads the page index.php . 上面的输入将带您到正确的目录并加载页面index.php

The redirects are set up as follows: 重定向设置如下:

header("Location: products.php");

Instead of going to mywebsite.myaccountname.host.com/products.php on the newhost, it goes to mywebsite.products.php on the old host. 与其转到新主机上的mywebsite.myaccountname.host.com/products.php ,不如转到旧主机上的mywebsite.products.php

Note I did name my subdomain on the new host mywebsite--the same as the domain of the current website, but I can't see how that would matter. 请注意,我确实在新主机mywebsite上命名了我的子域,该子域与当前网站的域相同,但是我看不出它的重要性。

Thanks for any suggestions of what could be causing this. 感谢您对可能导致此问题的任何建议。

try to use: 尝试使用:

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

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

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