How to Register Magento "404" Pages

I am running the Magento community site (in version 1.5.1) and I have a problem with the 404 pages.

We have users landing on our site, from direct links, as well as from google / bing search results. The pages they go to may be incorrect, as they may have changed. Magento uses MVC to route requests to the correct controller, but when there is no controller, Magento displays a static CMS page (i.e., the "404" page). The problem is that this page does not allow me to write my own PHP code, so I can not register the URL that called 404.

If I can find the correct point in the code before displaying the CMS 404 page, then I can register the URL and use it to rewrite the URL accordingly.

Can someone help me in where is the code that finally gives up on any controller and displays the CMS "404" user page?

+4
source share
2 answers

This mainly happens in Mage_Cms_IndexController::noRouteAction() . But you can also just look at the log of your web servers for entries with a return code 404 (404 is set in the same method).

+4
source

Alex was calm with his answer. I thought I would post the code I wrote to solve the problem based on its answer.

 /** * Render CMS 404 Not found page * * @param string $coreRoute */ public function noRouteAction($coreRoute = null) { $this->getResponse()->setHeader('HTTP/1.1','404 Not Found'); $this->getResponse()->setHeader('Status','404 File not found'); /* JCS */ $path = $this->getRequest()->getPathInfo(); if (!startsWith($path, '/media/')) { if (!startsWith($path, '/images/')) { if (!startsWith($path, '/ebay/')) { if (!startsWith($path, '/app/')) { Mage::log('JCS:noRouteAction:path:'.$path); } } } } $pageId = Mage::getStoreConfig(Mage_Cms_Helper_Page::XML_PATH_NO_ROUTE_PAGE); if (!Mage::helper('cms/page')->renderPage($this, $pageId)) { $this->_forward('defaultNoRoute'); } } 

I also added the startsWith function:

 /* JCS */ function startsWith($haystack, $needle) { $length = strlen($needle); return (substr($haystack, 0, $length) === $needle); } 
+1
source

Source: https://habr.com/ru/post/1401130/


All Articles