【问题标题】:Whats wrong with this 403 error redirect这个 403 错误重定向有什么问题
【发布时间】:2009-08-15 01:17:54
【问题描述】:

您好为 joomla 创建了一个 error.php 以将 404 错误等重定向到 joomla 文章。下面的代码适用于 404 错误,但 403 会返回空白页。我可以直接在我的脚本之外导航到该页面,因此它必须是我的代码或者它在其环境中的交互方式。

谢谢 斯蒂芬

defined( '_JEXEC' ) or die( 'Restricted access' );
if ($this->error->code == 404)
{
Header( "HTTP/1.1 404 Not found" );
header("Location: http://www.queensberry.com/misc/filenotfound/");
} else if ($this->error->code == 403) {
Header( "HTTP/1.1 403 Restricted Content" );
Header( "Location: http://www.queensberry.com/restrictedcontent/" ); 
} else {
echo "hello world error code = " . $this->error->code;
}
?>

【问题讨论】:

  • 您是否尝试过使用小写 header() 进行 403 重定向?
  • 函数在 PHP 中不区分大小写

标签: php joomla webserver http-status-code-404 http-status-code-403


【解决方案1】:

而不是使用Header("Loaction:..."),您应该使用include() 或类似的方式呈现“受限内容”页面,然后退出。浏览器很可能在收到 403 后没有跟随 Location 标头。

【讨论】:

  • 感谢 Steven 和 gnarf。 gnarf 你是说,与其像现在这样等待受限页面被退回,我应该编辑该页面以输出我的错误消息或从那里控制重定向>不确定我是否完全理解。干杯斯蒂芬
  • 我使用了一个框架,所以我的 404/403 有点不同,但我的所有经验告诉我,如果你有某种可以包含的 403.php 文件,你的问题就会消失( 403.php);它只会直接吐出错误页面。我认为这是服务器在给出错误代码时显示错误页面的预期行为。
【解决方案2】:

我感谢大家的帮助,但答案让我朝着与我所希望的方向不同的方向前进。我想继续使用 Joomla 的 error.php 文件作为 Joomla 错误的目的地,但我不想将页面格式化为看起来像是我想重定向到 Joomla 内容的网站的一部分。

最后我发现我需要的是一个出口;在我的脚本中。所以这里是error.php,因为它现在正在工作。

defined( '_JEXEC' ) or die( 'Restricted access' );
if ($this->error->code == 404)
{
Header( "HTTP/1.1 404 Not found" );
header("Location: http://www.queensberry.com/misc/filenotfound/");
exit;
} else if ($this->error->code == 403) {
Header( "HTTP/1.1 403 Restricted Content" );
Header( "Location: http://www.queensberry.com/restrictedcontent/" ); 
exit;
} else {
echo "hello world error code = " . $this->error->code;
}
?>

【讨论】:

    【解决方案3】:

    Header("Location:") 导致标准重定向到新页面。只有在 PHP 呈现的页面上才会发送 403 错误。因此,您实际上是在尝试说(使用您发布的代码)“当前页面导致 403 错误”,但随后您完全重定向到一个完全不同的页面。将 403 标头添加到http://www.queensberry.com/restrictedcontent/,您应该会很好。您还需要对 404 标头执行相同操作。

    【讨论】:

      【解决方案4】:

      如果 (HTTP/1.1 403) 那么 Web 浏览器 (Firefox, IE, Chrome, ...) 将忽略任何东西

      位置:(bla bla bla)是。

      不信?

      假设 :: 您知道如何从您的 Joomla 站点生成错误代码 403。 (我的意思是产生错误代码 403 的 joomla_site/bla-bla-bla ::)

      让我们问一下Web Server是否给出(基于你的error.php文件)如下:

      ... HTTP/1.1 403 受限内容 地点:http://www.queensberry.com/restrictedcontent/ ...

      根据您的 error.php 文件,这些是正确的(我的意思是 您的 error.php 文件可以按照您的意愿工作

      -- 使用 telnet 80 检查

      我们试试

      c:\telnet your_host:80

      GET bla-bla-bla HTTP/1.1

      主机:joomla_site

      -- 希望这能满足你的好奇心 :-)

      我再重复一遍:

      如果 (HTTP/1.1 403) 那么 Web 浏览器 (Firefox, IE, Chrome, ...) 将忽略任何东西

      位置:(bla bla bla)是。

      【讨论】:

        猜你喜欢
        • 2022-12-04
        • 1970-01-01
        • 2010-12-09
        • 1970-01-01
        • 2023-03-26
        • 1970-01-01
        • 2012-07-04
        • 1970-01-01
        相关资源
        最近更新 更多