I wrote an extension for Magento that, under certain circumstances, triggers a 404 redirect from the controller. Code in the controller that causes 404 redirection:
$this->getResponse()->setHeader('HTTP/1.1','404 Not Found'); $this->getResponse()->setHeader('Status','404 File not found'); $pageId = Mage::getStoreConfig('web/default/cms_no_route'); if (!Mage::helper('cms/page')->renderPage($this, $pageId)) { $this->_forward('defaultNoRoute'); }
This code is accessed via the URL www.mysite.com/mymodule/index/action?name=value, and redirection is triggered based on the "value".
However, since my module contains a layout update that overwrites the root of the node:
<layout version="0.1.0"> <mynamespace_mymodule_index_action> <block type="mymodule/list" name="root" template="mynamespace/mymodule/list.phtml" output="toHtml" /> </mynamespace_mymodule_index_action> </layout>
404 redirection shows a blank (white) page containing the following HTML:
<head> </head> <body> <div id="outerdivshade"> <div id="outerdivpadding"> <div class="wrapper"> <div class="page"> <div class="main-container col2-left-layout"> <div class="main"> <div class="col-main"></div> <div class="col-left sidebar"></div> </div> </div> </div> </div> </div> </div> </body>
I assume that when updating the root of the node, I left a layout structure that the redirect code cannot work with to create a full 404 page.
By removing the if statement and leaving only the code:
$this->_forward('defaultNoRoute');
everything works, but I do not understand the pros and cons of this.
Interestingly, the above code works correctly on Magento 1.6, but not 1.7.
I would appreciate any comments on the correct way to enable working 404 redirection, but still letting me use my own root node in the layout.
thanks