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


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.

            <customcatalog before="Mage_Catalog">Amit_Customcatalog</customcatalog>

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('');
                } elseif (!$this->getResponse()->isRedirect()) {
                   // $this->_forward('noRoute');

            } else {

              //  $this->_forward('noRoute');
  • 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 you have read our privacy policy.

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