My Magento store experiences a high amount of products that get added and then deleted. I have been asked to implement a 410 status code on these deleted pages but I am unsure how.
Looking at magento's core code i can see it handles 404's like so in the core indexController:
/**
* Default index action (with 404 Not Found headers)
* Used if default page don't configure or available
*
*/
public function defaultIndexAction()
{
$this->getResponse()->setHeader('HTTP/1.1','404 Not Found');
$this->getResponse()->setHeader('Status','404 File not found');
$this->loadLayout();
$this->renderLayout();
}
/**
* 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');
$pageId = Mage::getStoreConfig(Mage_Cms_Helper_Page::XML_PATH_NO_ROUTE_PAGE);
if (!Mage::helper('cms/page')->renderPage($this, $pageId)) {
$this->_forward('defaultNoRoute');
}
}
/**
* Default no route page action
* Used if no route page don't configure or available
*
*/
public function defaultNoRouteAction()
{
$this->getResponse()->setHeader('HTTP/1.1','404 Not Found');
$this->getResponse()->setHeader('Status','404 File not found');
$this->loadLayout();
$this->renderLayout();
}
Is there any way I can add a function to a deleted page to send a 410 header?
catalog_product_delete_beforeevent and in my custom module class i have the functionstoreDeletedUrl. Inside this function how do I get the url path of the product to be deleted? – odd_duck Sep 07 '15 at 10:46storeDeletedUrlsupposed to do and where do you call it? – Fabian Schmengler Sep 07 '15 at 10:50DeletedUrlsSaveand in my config.xml i have<events><catalog_category_delete_before><observers><company_deletedurlssave><type>model</type><class>Company_DeletedUrlsSave_Model_DeletedUrlsSave</class><method>storeDeletedUrl</method>….so i observe the event and call thestoreDeletedUrlfunction in my classCompany_DeletedUrlsSave_Model_DeletedUrlsSave– odd_duck Sep 07 '15 at 10:58$product_id = $observer->getProduct()->getId(); $rewriteCollection = Mage::getResourceModel('core/url_rewrite_collection')->addFieldToFilter('id_path', array('regexp' => "^product/{$product_id}(\$|/)"));to get a collection of all rewrites for this product. You can loop over it and callgetRequestPath()on each item to get the URLs – Fabian Schmengler Sep 07 '15 at 11:13