Php PrestaShop:如果产品没有';不存在

Php PrestaShop:如果产品没有';不存在,php,prestashop,url-redirection,prestashop-1.6,Php,Prestashop,Url Redirection,Prestashop 1.6,我试图像这样重定向页面: 我希望删除id_产品的每个页面都将重定向到我的主页: 这意味着:我要重定向“” 如何在htaccess文件中执行此操作?也许这会有所帮助 编辑文件controllers/front/ProductController.php,行91或查找Tools::displayError('Product not found'),并将其更改为: 标题(“位置:/”我提出了@Labradorcode的想法,但方法是正确的。 在rootofps/override/controller

我试图像这样重定向页面:

我希望删除id_产品的每个页面都将重定向到我的主页:

这意味着:我要重定向“”


如何在htaccess文件中执行此操作?

也许这会有所帮助

编辑文件
controllers/front/ProductController.php
,行
91
或查找
Tools::displayError('Product not found')
,并将其更改为:


标题(“位置:/”

我提出了@Labradorcode的想法,但方法是正确的。 在
rootofps/override/controllers/front/ProductController.php
中对ProductController.php进行更新,因此您必须在该目录中创建一个新文件(对于rootofps,我指的是PrestaShop的安装目录),该文件的内容如下所示:

class ProductController extends ProductControllerCore {
    public function init(){
        FrontController::init();

        if ($id_product = (int)Tools::getValue('id_product')) {
            $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id);
        }

        if (!Validate::isLoadedObject($this->product)) {
            header('HTTP/1.1 404 Not Found');
            header('Status: 404 Not Found');
            header('Location: '.$this->context->link->getPageLink('index', array('id_product', Tools::getValue('id_product'))));
        } else {
            parent::init();
        }
    }
}
在这种情况下,如果产品被完全移除,而不是被禁用,则重定向有效


创建文件后,删除此文件
rootofps/cache/class_index.php

需要htaccess,甚至需要通过php?可能是通过php…我不知道如何通过php重定向。我想你不能在
.htaccess
中执行此操作,因为Apache不知道产品是否已删除。您必须在产品控制器中执行,就像@LabradorCodeThank建议的那样。现在我得到了这个错误:公共类ProductController扩展ProductControllerCore{public function init(){FrontController::init();if($id_product=(int)Tools::getValue('id_product')){$this->product=new product($id_product,true,$this->context->language->id,$this->context->shop->id);}if(!Validate::isLoadedObject($this->product)){header('HTTP/1.1 404未找到');header('Status:404未找到');header('Location:'。$this->context->link->getPageLink('index',array('id_product',Tools::getValue('id_product'));}否则{parent::init init();}致命错误:在第134行的/…/classes/controller/controller.php中找不到类“ProductController”,是否遵循了“说明”?你有哪个版本的prestashop?我用的是1.6.1.4。我已经将ProductController.php添加到override/controller/front/,并删除了class_index.phpI。很抱歉,从类声明中删除public。我的错。PS:正确的路径是override/controller
s
/front,controller with
s
:)您的意思是编辑override文件还是核心文件?是的-我试过了-它不起作用…它一直在显示没有产品的页面。还有其他吗?