目前,我有一个可通过以下域访问的脚本
http://me.domain.com/path/index.php
如果满足特定条件,我将通过使用执行重定向回到自身
header('Location: index.php');
重定向后,大多数主要浏览器将结束于
http://me.domain.com/path/index.php
还是。但是,对于某些第 3 方供应商的浏览器(用于 sim 卡模拟目的),它们最终将位于 (注意缺少的路径)
http://me.domain.com/index.php
我想知道,这是因为第 3 方供应商没有正确实现他们的浏览器吗?或者,不同的浏览器在处理重定向时产生不同的行为是可以的吗?
我意识到如果我使用下面的代码,
// $_SERVER['PHP_SELF'] is /path/index.php
header('Location: '.$_SERVER['PHP_SELF']);
它将在所有浏览器中工作,不会丢失路径。
最佳答案
嗯manual说:
Most contemporary clients accept relative URIs as argument to » Location:, but some older clients require an absolute URI including the scheme, hostname and absolute path. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself:
简而言之,始终使用完整的 URI 来涵盖所有情况
关于php - header 重定向是否在不同的浏览器中产生不同的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34388882/