PHP重定向子域的问题(PHP Redirect problem with subdomain)

编程入门 行业动态 更新时间:2024-10-25 12:16:44
PHP重定向子域的问题(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

I'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?

更多推荐

本文发布于:2023-08-05 05:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1427543.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   PHP   Redirect   subdomain   problem

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!