6

I want to redirect every 404 product to catalog search because I have anothers products with similar name.

I have a lot of products are more them 1000 products with 404, that dont exist any more, but those old link are published in another websites and users still came from that links, so to keep the user on my website I want to redirect this broke link to catalog search, NOTE: "cant do it on magento rewrite url product by product because those product dont exist anymore"

I am thinking to do some route on source code to do some like this:

OLD link: http://www.mywebsite.com/iphone-5-16GB.html -> broke link

REDIRECT TO: http://www.mywebsite.com/catalogsearch/result/?q=iphone+5+16gb

I cant find any solution here on stackoverflow and nothing on Google results.

How can I do that?

1 Answer 1

3

You can do this by override ProductController.php (Mage_Catalog_ProductController) and on view action put cod for redirection. to catalog searcg page.

How to override a controller,please check here.

     <frontend>
    <routers>
     <frontend>
    <routers>
        <catalog>
        <args>
            <modules>
            <customcatalog before="Mage_Catalog">Amit_Customcatalog</customcatalog>
            </modules>
        </args>
        </catalog>
    </routers>
</frontend>

and put some code viewAction function:

  ..... 
   try {
            $viewHelper->prepareAndRender($productId, $this, $params);
        } catch (Exception $e) {
            if ($e->getCode() == $viewHelper->ERR_NO_PRODUCT_LOADED) {
                if (isset($_GET['store'])  && !$this->getResponse()->isRedirect()) {

                 //   $this->_redirect('');
        $this->_redirect('catalogsearch/result/',array('q'=>'$quertString));
        return;
                } elseif (!$this->getResponse()->isRedirect()) {
                   // $this->_forward('noRoute');
        $this->_redirect('catalogsearch/result/',array('q'=>'$quertString));
        return;

                }
            } else {
                Mage::logException($e);
        $this->_redirect('catalogsearch/result/',array('q'=>'$quertString));
        return;

              //  $this->_forward('noRoute');
            }
        }
1
  • I want the same functionality but in magento 2.2.3. please help
    – Ashna
    Jun 26, 2018 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.