有没有办法检查谁或什么导致重定向?
Is there a way to check who or what is causing a redirect?
我的项目(使用复杂的 framework/cms)基于 PHP、.htaccess、JS 等进行重定向...我正在努力寻找导致特定重定向的原因。虽然我看到使用通用工具(RedirectChecker、Browser-Dev-Tools ...)的重定向,但我看不到 who/what 是导致它的原因。有没有通用的方法来找出例如
- foo.de -> 301 -> www.foo.de (.htaccess line:4711)
- www.foo.de -> 301 -> www.foo.com/de/ (somefile.php line:666)
注意:我可以访问服务器。
您无法从客户端检查 server-sided redirection
是如何触发的。但是,您可以在每次重定向时添加自定义 HTTP Headers
。
PHP中的示例:
header('HTTP/1.1 301 Moved Permanently by PHP script');
应该出现在 Firebug 或其他检查器工具中。
备选方案(没试过)是:
header('HTTP/1.1 301 Moved Permanently');
header('Redirected from index.php');
对于 .htaccess 重定向,您可以打开重写登录 RewriteLog. For php rewrites what you can do is force output to the browser (see flush
and ob_flush
)。当框架尝试设置 headers 时,例如位置 header.
,将产生错误
你也可以看看override_function
to overwrite the header function, check if location header is send and log it to file or throw an exception or error. You can get the trace using debug_backtrace
。您将 PECL apd >= 0.2
使用 override_function
一种激进的(但在某种意义上是最正确的)处理方法是将项目中所有出现的 header()
替换为 my_header()
并编写 my_header
以便它记录其参数并将它们进一步传递给 php 的 header
。如果你的 FW 使用命名空间,你可以简单地添加你自己的 header
到 NS。
如果无法更改 FW 代码,则需要 runkit 或 sorts 来挂接全局函数。
我的项目(使用复杂的 framework/cms)基于 PHP、.htaccess、JS 等进行重定向...我正在努力寻找导致特定重定向的原因。虽然我看到使用通用工具(RedirectChecker、Browser-Dev-Tools ...)的重定向,但我看不到 who/what 是导致它的原因。有没有通用的方法来找出例如
- foo.de -> 301 -> www.foo.de (.htaccess line:4711)
- www.foo.de -> 301 -> www.foo.com/de/ (somefile.php line:666)
注意:我可以访问服务器。
您无法从客户端检查 server-sided redirection
是如何触发的。但是,您可以在每次重定向时添加自定义 HTTP Headers
。
PHP中的示例:
header('HTTP/1.1 301 Moved Permanently by PHP script');
应该出现在 Firebug 或其他检查器工具中。
备选方案(没试过)是:
header('HTTP/1.1 301 Moved Permanently');
header('Redirected from index.php');
对于 .htaccess 重定向,您可以打开重写登录 RewriteLog. For php rewrites what you can do is force output to the browser (see flush
and ob_flush
)。当框架尝试设置 headers 时,例如位置 header.
你也可以看看override_function
to overwrite the header function, check if location header is send and log it to file or throw an exception or error. You can get the trace using debug_backtrace
。您将 PECL apd >= 0.2
使用 override_function
一种激进的(但在某种意义上是最正确的)处理方法是将项目中所有出现的 header()
替换为 my_header()
并编写 my_header
以便它记录其参数并将它们进一步传递给 php 的 header
。如果你的 FW 使用命名空间,你可以简单地添加你自己的 header
到 NS。
如果无法更改 FW 代码,则需要 runkit 或 sorts 来挂接全局函数。