Prestashop重定向的网址不正确

问题描述 投票:0回答:1

我需要帮助,我需要将不正确的网址重定向到404页我的意思是:

这是确切的网址http://something.com/2-sport-shoes

但是如果我写http://something.com/2-dsajdhasudhas因此它重定向到与其ID相同的网址

在Prestashop中如何将不正确的URL重定向到4O4?

url redirect http-status-code-404 prestashop
1个回答
0
投票

解决方案

修改CategoryController

public function canonicalRedirection($canonical_url = '')
    {
        if (Tools::getValue('live_edit')) {
            return;
        }
        if (!Tools::getValue('noredirect') && Validate::isLoadedObject($this->category)) {
            $exact_url= parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
            $link = $this->category->id . "-" . $this->category->link_rewrite;
            if($exact_url != $link) {
                Tools::redirect('index.php?controller=404');

            }
        }
    }
© www.soinside.com 2019 - 2024. All rights reserved.