我正在使用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.phpI'm using PHP to redirect a page back to the previous page with the following:
header("Location: {$_SERVER['HTTP_REFERER']}");This set of pages will only be used by internal users, so I'm not terribly concerned about the fact that the referer will not always be available.
The problem I'm running in to is that if the referer looks like http://subdomain.domain.com/test.php?id=13, the redirect ends up going to http://subdomain.domain.com/.domain.com/test.php?id=13. Notice the additional .domain.com/ in the url.
I've tested by hardcoding the value, and it causes the problem as well. phpMyAdmin seems to suffer the same issue, but only on this particular server.
If this is not an SO question, please move accordingly.
EDIT: per @yaggo
test.php contains only 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最满意答案
您的nginx配置似乎导致了问题。
完全有可能nginx正在修改响应头。 这不是默认情况下 - 您可能有一个旨在使其充当反向代理等的配置。
您是否尝试使用其默认配置测试nginx上的重定向?
It seems that your nginx configuration is causing the problems.
Its totally possible that nginx is modifying the response headers. This is not by default - you could have a configuration that is aimed for it to behave as a reverse proxy etc.
Have you tried testing the redirect on a nginx with its default configuration?
更多推荐
发布评论