【问题标题】:how to make Prestashop 404 error pages redirected to homepage, and not to default template?如何使 Prestashop 404 错误页面重定向到主页,而不是默认模板?
【发布时间】:2016-11-14 13:36:10
【问题描述】:

如何使 Prestashop 404 错误页面重定向到主页,而不是默认模板? 我确实尝试了一切 - 没有任何效果。 我确实把它放在 .htacess -> 不工作, 我也将它放在 404.tpl 文件中,在头部使用 javascript 手动重定向,遗憾的是它不接受更改并且无法正常工作。 我无法找到它的声明位置以及将 404 错误重定向到这个糟糕的模板页面的位置。 从 SEO 的角度来看,这真的很痛。 请帮我。 谢谢。

(从 5 天开始一​​直试图解决这个问题,但我走到了死胡同。 你是我唯一的希望。请帮忙!)

【问题讨论】:

  • 您是否在.htaccess 中写过类似ErrorDocument 404 /index.php 的内容?你试过<?php header("Location: index.php");?>吗?
  • 在哪里?在 .htacess 中?
  • .htacess 中的 php 代码?这可能吗?
  • 我确实尝试将其放入 .htacesss - 没用,它破坏了 ws。
  • 如果您不知道 - 将 404 重定向到主页将使它们成为软 404 seroundtable.com/301-pages-home-soft-404-22811.html

标签: php html redirect seo prestashop


【解决方案1】:

在 override/controllers/front/PageNotFoundController.php 中创建覆盖:

class PageNotFoundController extends PageNotFoundControllerCore
{
    public function initContent()
    {   
        header('HTTP/1.1 301 Moved Permanently');
        Tools::redirect(__PS_BASE_URI__);
        exit();
    }
}

问候

【讨论】:

  • 我把它放在文件的哪个位置有关系吗?
  • 你在我的回答中占有一席之地。
  • 谢谢,让我试一试,然后我再打字说发生了什么
  • /override/controllers/front/ 文件夹中没有文件“PageNotFoundController.php”。该怎么办?在哪里搜索它? /controllers/front/PageNotFoundController.php 中有相同的文件 - 是相同的文件吗?
  • 这是该文件中 php 代码的一部分: class PageNotFoundControllerCore extends FrontController { public $php_self = 'pagenotfound';公共 $page_name = 'pagenotfound';公共 $ssl = true;
【解决方案2】:

我不完全了解 Prestashop,但据我所知,您有类似的课程:

class PageNotFoundControllerCore extends FrontController
{
    public $php_self = 'pagenotfound';
    public $page_name = 'pagenotfound';
    public $ssl = true;
    /**
     * Assign template vars related to page content.
     *
     * @see FrontController::initContent()
     */
    public function initContent()
    {
        header("Location: index.php") // delete everything here and add this line.
    }

它可能存储在那里:

PrestaShop/controllers/front/PageNotFoundController.php GitHub

如您所见,您可以在上面添加header("Location index.php")。在"Location <redirect_location>" 的地方,您可以写下您想要重定向的位置。更多信息请到PHP Manual: header

【讨论】:

  • 你能告诉我具体怎么做吗? - 我的意思是在哪里粘贴它......在哪个文件中。
  • 这一切都在文件“/controllers/front/PageNotFoundController.php”中,所以可能是它的错误文件?
  • 现在检查,我想我找到了这个文件
猜你喜欢
  • 2010-12-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-10
  • 2012-09-11
  • 1970-01-01
相关资源
最近更新 更多