这个 403 错误重定向有什么问题

发布于 2024-08-02 11:51:30 字数 600 浏览 2 评论 0原文

您好,为 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;
}
?>

Hi have created a error.php for joomla to redirect 404 errors etc to a joomla article. The code below works for a 404 error, but a 403 returns a blank page. I can navigate to the page directly outside my script so it must be either my code or how it is interactive in it's environment.

Thanks
Stephen

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;
}
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

暖伴 2024-08-09 11:51:30

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

Rather than using Header("Loaction:...") you should be rendering the "restricted content" page with an include() or some such and then exiting. The browser isn't following the Location header after receiving a 403 most likely.

才能让你更想念 2024-08-09 11:51:30

我感谢每个人的帮助,但答案让我朝着与我所希望的不同的方向发展。我想继续使用 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;
}
?>

I appreciate everyone's help, but the answers were sending me in a different direction to what I was hoping for. I wanted to continue using Joomla's error.php file as the destination for Joomla errors but instead of formatting the page to look like it was part of the site I wanted to redirect to Joomla content.

In the end I found what I needed was an exit; in my script. So here is the error.php as it is now working.

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;
}
?>
秋千易 2024-08-09 11:51:30

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

The Header("Location:") is causing a standard redirect to a new page. The 403 error will only be sent if it is on the page rendered by PHP. So you're effectively trying to say (with the code you posted) "The current page results in a 403 error" but then you redirect to an entirely different page altogether. Add the 403 header to http://www.queensberry.com/restrictedcontent/ and you should be good. You also need to do the same with the 404 header as well.

初心 2024-08-09 11:51:30

如果 (HTTP/1.1 403) 则网络浏览器(Firefox、IE、Chrome...)将忽略任何

位置:(bla bla bla)。

不相信?

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

让我们询问 Web 服务器 是否给出(基于您的 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) 则网络浏览器(Firefox、IE、Chrome、. ..) 将忽略任何

位置:(bla bla bla)。

If (HTTP/1.1 403) then Web Browser (Firefox, IE, Chrome, ...) will ignore whatever

Location: (bla bla bla) is.

Do not believe ?

Assume :: you know how to produce Error Code 403 from your Joomla Site.
(I mean joomla_site/bla-bla-bla :: that produce Error Code 403)

Let's ask whether Web Server gives (based on your error.php file) as follows :

...
HTTP/1.1 403 Restricted Content
Location: http://www.queensberry.com/restrictedcontent/
...

Those are right based on your error.php file (I mean your error.php file works as you wish)

-- Check with telnet 80

Let's try

c:\telnet your_host:80

GET bla-bla-bla HTTP/1.1

Host: joomla_site

-- Hope this fulfill your curiosity :-)

I repeat it again :

If (HTTP/1.1 403) then Web Browser (Firefox, IE, Chrome, ...) will ignore whatever

Location: (bla bla bla) is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文