dongyu9667 2014-10-27 04:09
浏览 30
已采纳

Joomla自定义错误页面不能正常工作

For a long time I'm trying to enable custom 404 page for my joomla 2.5 website, because default red error page was not an option.

I enabled it, however, it shows only if user enters site.com/wrong_page and if users enter url of the following structure site.com/wrong_page/wrong_page it doesn't show anything, just blank empty page.

So, If user goes to a page "Goods" and then goes to unexisting item site.com/goods/wrong_itemid it wouldn't show custom error, it shows nothing, but if user opens site.com/wrong_link he will see custom error page.

Please, help me to sort this out.

I used the following in error.php:

switch ($this->error->code) {
   case '404':
      header('location: /404-page');
      break;
   case '500':
      include('500.php');
      break;
   case '403':
      include('403.php');
      break;
   default:
      header('location: /404-page');
    }
  • 写回答

2条回答 默认 最新

  • dtv8189 2014-10-28 02:16
    关注

    This is what I did in Joomla 2.5

    • create your custom '404' Article

    • create a new unpublished menu item which links to this new 404 Article and 'apply' your changes. Copy the URL for this page (index.php?optio...)

    • in your Joomla installation, copy the error.php file from the templates/system directory to your template directory.

    • Edit the error.php file and add the following code immediately under the 'restricted access' line:

      if (($this->error->getCode()) == '404') {
      header('Location: /index.php?option=com_content&view=article&id=xx');
      exit;
      }

    UPDATE
    The above technique is intended as an easy way to make a custom page. You can use the built-in Joomla text editor and the page will match your site styling. @Flimm has correctly pointed out below that the page will no longer give a 404 HTTP header. If you are concerned about this, another option is: - in your Joomla installation, copy the error.php file from the templates/system directory to your template directory.

    • Open the copy of error.php in your template directory with any text editor and edit the HTML within the <body> tag however you like.

    Good luck!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?