子域的PHP重定向问题

标签 php redirect

我正在使用 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/

相关文章:

ruby-on-rails - Rails : When testing controllers with RSpec, 如何阻止它们重定向?

batch-file - 在批处理中插入带有重定向的换行符

php - Codeigniter 删除所有 html 标签

php - 在 PHP 中动态生成 XML - 解析错误

php - Symfony 服务作为全局 Twig 变量

php - MySQL 使用 PHP 更新查询导致 AJAX 错误回调

.htaccess - 某些网址的 301 重定向无效

cakephp - "too many redirects"在 heroku 上使用 CakePHP 的 SSL 重定向

redirect - 使用一个域使另一个域内容看起来受 HTTPS 保护(HTTPS 重定向到我无权访问的网站)

php - 提交表单并使用 PHP 通过电子邮件发送