Magento: force redirect to 404

15.Apr.2013

If you ever find a need to, as a result of your custom action, display the 404 page to customer, you can do it by using the following code inside your controller class

1
2
3
$this->getResponse()->setHeader('HTTP/1.1','404 Not Found');
$this->getResponse()->setHeader('Status','404 File not found');
$this->_forward('defaultNoRoute');

This way you’ll be calling the default Magento dispatcher and it will set the 404 headers and display the 404 page you set as a default 404 page in your Magento admin.