0

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.

I have installed a extension

Magento-2-Module-PageNotFound

But its only listing the URLs which going to 404 pages.

How can I set all 404 pages to 410 status.

Can I get some help? Thank you in advance.

2
  • You just want to set them in 410 status and not redirect them anywere? Sep 6, 2021 at 11:26
  • @Alan Zavagli Thank you for response. yes Sep 6, 2021 at 12:32

1 Answer 1

0

I have found the solution for this.

I have user this plugin to catch the 404 urls

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <type name="Magento\Cms\Controller\Noroute\Index">
        <plugin name="trackNoRoutePages"
                type="Experius\Pvn\Controller\Plugin\TrackNoRoutePages"/>
    </type>
</config>

Here am redirecting them to 410 gone page which I created in Page from content>>pages. and setting headers to 410

<?php

namespace Experius\Pvn\Controller\Plugin;

class TrackNoRoutePages
{
    public function afterExecute(
        \Magento\Cms\Controller\Noroute\Index $subject,
        $return
    ) {

        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $redirect = $objectManager->get('\Magento\Framework\App\Response\Http');

        $storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
        $base_url=$storeManager->getStore()->getBaseUrl();
        

        $redirect->setRedirect($base_url.'410-gone');
        $redirect->setStatusHeader(410, '1.1', 'Gone');
        $redirect->setHeader('Status', '410 Gone');

        return $redirect;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.