title: Magento how to trigger a 404 redirect from controller when extension overwrite root layout node
body: <p>I've written an extension for Magento which will initiate a 404 redirect from the controller under certain circumstances. The code in the controller that causes the 404 redirect is:</p>
  
  <pre><code>$this-&gt;getResponse()-&gt;setHeader('HTTP/1.1','404 Not Found');
  $this-&gt;getResponse()-&gt;setHeader('Status','404 File not found');
  $pageId = Mage::getStoreConfig('web/default/cms_no_route');
  if (!Mage::helper('cms/page')-&gt;renderPage($this, $pageId)) {
      $this-&gt;_forward('defaultNoRoute');
  }
  </code></pre>
  
  <p>This code is accessed via the URL www.mysite.com/mymodule/index/action?name=value and the redirect is triggered based on 'value'.</p>
  
  <p>However, because because my module contains a layout update which overwrites the root node:</p>
  
  <pre><code>&lt;layout version="0.1.0"&gt;
      &lt;mynamespace_mymodule_index_action&gt;
          &lt;block type="mymodule/list" name="root" template="mynamespace/mymodule/list.phtml" output="toHtml" /&gt;
      &lt;/mynamespace_mymodule_index_action&gt;
  &lt;/layout&gt;
  </code></pre>
  
  <p>the 404 redirect is showing a blank (white) page, which contains the following HTML:</p>
  
  <pre><code>&lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id="outerdivshade"&gt;    
          &lt;div id="outerdivpadding"&gt;
              &lt;div class="wrapper"&gt;
                  &lt;div class="page"&gt;
                      &lt;div class="main-container col2-left-layout"&gt;
                          &lt;div class="main"&gt;
                              &lt;div class="col-main"&gt;&lt;/div&gt;
                              &lt;div class="col-left sidebar"&gt;&lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>I'm guessing that by updating of the root node I've left a layout structure that the redirect code cannot work with to create the complete 404 page.</p>
  
  <p>By removing the if statement and leaving just the code:</p>
  
  <pre><code>$this-&gt;_forward('defaultNoRoute');
  </code></pre>
  
  <p>everything works, but I don't understand the pros and cons of doing this.</p>
  
  <p>Interestingly the above code works correctly on Magento 1.6, but not on 1.7.</p>
  
  <p>I'd appreciate any comments on the <em>right</em> way of including a working 404 redirect, but still allowing me to use my own root node in the layout.</p>
  
  <p>Thanks</p>