[英]PHP Redirect problem with subdomain
我正在使用PHP将页面重定向回上一页,其中包含以下内容:
header("Location: {$_SERVER['HTTP_REFERER']}");
这组页面仅供内部用户使用,因此我并不十分关注引用者不会始终可用的事实。
我遇到的问题是,如果引用者看起来像http://subdomain.domain.com/test.php?id=13
,则重定向最终会转到http://subdomain.domain.com/.domain.com/test.php?id=13
。 请注意网址中的其他.domain.com/
。
我通过硬编码测试了这个值,它也导致了问题。 phpMyAdmin
似乎遇到了同样的问题,但只在这个特定的服务器上。
如果这不是问题,请相应地移动。
编辑 :每@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和不同的网络服务器,所以有两件事需要调查。
[...]重定向最终会转到http://subdomain.domain.com/.domain.com/test.php?id=13 。
你能更多地解决这个问题吗? 这个网址究竟是PHP返回的内容,还是浏览器(Chrome?)看到的内容?
你能检查实际的标题,例如curl:
$ curl --head --referer 'http://your-referer' 'http://your-page/'
您的nginx配置似乎导致了问题。
完全有可能nginx正在修改响应头。 这不是默认情况下 - 您可以拥有一个旨在使其充当反向代理等的配置。
您是否尝试使用其默认配置测试nginx上的重定向?
header("Location: ".$_SERVER['HTTP_REFERER']);
编辑:
检查.htaccess设置或如果没有找到解决方案你可以使用preg_replace删除最后一个“.domain.com”
但它看起来不是一个PHP错误。
或使用javascript获取引用地址...然后使用window.location.href = url; 重定向...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.