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条)

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测