我正在使用 PHP 将页面重定向回上一页:
header("Location: {$_SERVER['HTTP_REFERER']}");
这组页面将仅供内部用户使用,因此我并不十分担心 referer 并不总是可用这一事实。
我遇到的问题是,如果 referer 看起来像 http://subdomain.domain.com/test.php?id=13
,重定向最终会转到 http://subdomain.domain.com/.domain.com/test.php?id=13
。注意 url 中额外的 .domain.com/
。
我已经通过硬编码值进行了测试,它也会导致问题。 phpMyAdmin
似乎遇到了同样的问题,但仅限于此特定服务器。
如果这不是 SO 问题,请相应地移动。
编辑:根据@yaggo
test.php 只包含 header("Location: http://subdomain.domain.com/test2.php");
curl --head --referer 'http://subdomain.domain.com/' 'http://subdomain.domain.com/test.php'
HTTP/1.1 302 Found
Server: nginx/0.7.64
Date: Fri, 02 Apr 2010 17:21:45 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.2.12-pl0-gentoo
Location: .domain.com/test2.php
最佳答案
我已经在我的服务器上重新创建了您的两个程序 曾经与
header("Location: http://subdomain.domain.com/some/place");
曾经和
header("Location: {$_SERVER['HTTP_REFERER']}");
都给出了正确的结果
curl --head --referer 'http://subdomain.domain.com/some/place' 'http://subdomain.domain.com/test.php'
HTTP/1.1 302 Found
Date: Fri, 02 Apr 2010 17:48:54 GMT
Server: Apache/2.0.52 (Red Hat)
X-Powered-By: PHP/5.1.2
Location: http://subdomain.domain.com/some/place
Connection: close
Content-Type: text/html
我使用的是不同版本的 PHP 和不同的网络服务器,因此有两件事需要调查。
关于子域的PHP重定向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2501338/