【问题标题】:Joomla 403 redirect codeJoomla 403 重定向代码
【发布时间】:2020-10-30 00:24:04
【问题描述】:

当检测到403 时,我无法让 Joomla 3 将用户重定向到会员页面。

经过几天的研究和尝试各种事情,我终于屈服于不得不问这个问题。

根据我的研究,我了解到 Joomla 从 templates/system/error.php 主文件中读取。

我在error.php 中实现了以下代码,我也尝试通过.htaccess 强制执行它,但都不起作用。

$ReferTo = $_SERVER['REQUEST_URI'];
$ReferTo = base64_encode($ReferTo);

if ($this->error->getCode() == '403') {
header('Location: ' . $this->baseurl . '/members'); die();
}

当前的行为是 Joomla 只是将用户发送到一个非常无用的 403 默认页面。

关于这个有什么想法吗?非常感谢您的帮助。

【问题讨论】:

    标签: php .htaccess joomla


    【解决方案1】:

    幸运的是,我侥幸找到了解决方案。我将系统文件夹 error.php 文件放入所有单独的模板文件夹中以创建系统覆盖。到目前为止,Joomla 已经认识到这一点。

    【讨论】:

      【解决方案2】:

      在你的Joomla网站主目录下创建一个403.html文件,内容如下:

      <meta http-equiv="refresh" content="0; url=http://www.yourwebsite.com/members" />
      

      在您的 .htaccess 文件中,添加以下代码:

      ErrorDocument 403 /403.html
      

      如果您只想对某些请求执行此操作,则重定向到 .htaccess 文件中的 403.php 文件(而不是重定向到 403.html 文件),检查 REQUEST URI 以查看它是否确实来自会员区,然后重定向回会员页面。

      【讨论】:

      • 感谢您的建议。不幸的是,Joomla 仍然决定否决 HTACCESS 并继续重定向到它自己的 403 页面。幸运的是,我侥幸找到了解决方案。我将系统文件夹 error.php 文件放入所有单独的模板文件夹中以创建系统覆盖。到目前为止,Joomla 已经认识到这一点。
      【解决方案3】:

      Joomla 在尝试访问受保护的文章时创建/引发 403 事件。因此编辑文件 System / error.php 或在模板本身内不起作用。 .htaccess 或 httpd.conf 中使用 ErrorDocument 的其他解决方案也不起作用。

      我也试过代码 this-> error-> getCode () == '403',但没有触发。

      我找到的唯一解决方案是修改文章的 HTML 视图,以重定向到显示登录名和个性化消息的文章。

      要修改的文件是components/com_content/views/article/view.html.php第134到139行

      Joomla 3.9.20

      要替换的代码如下:

      
       // Check the view access to the article (the model has already computed the values).
                      if ($ item-> params-> get ('access-view') == false && ($ item-> params-> get ('show_noauth', '0') == '0'))
                      {
                              $ app-> enqueueMessage (JText :: _ ('JERROR_ALERTNOAUTHOR'), 'error');
                              $ app-> setHeader ('status', 403, true);
                              return;                        
                      }
      

      为此

                      // Check the view access to the article (the model has already computed the values).
                      if ($item->params->get('access-view') == false && ($item->params->get('show_noauth', '0') == '0'))
                      {
                              header('Location:https://www.yourwebpage/withLoginandCustomMessage.php');
                       die();
                      }
      
      

      这只会向尝试查看需要注册或使用其他 ACL 的文章的用户显示。

      我知道我们不应该编辑文件,因为在 Joomla 更新中,这些更改可能会丢失,但这是我找到的唯一解决方案(模块或插件都没有解决这个问题,显然它是来自joomla 1.5)。

      【讨论】:

      • 如果您不确定如何在不破解核心文件的情况下修改您的 Joomla 应用程序,您可能想在Joomla Stack Exchange 上询问是否有人可以帮助您以更稳定的方式执行此技术。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-04
      • 2014-01-03
      • 2018-12-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多