0

I am trying to redirect url to my custom no route found page but it always redirect to default 404 page,

I have made below changes in my module

Step-1 Create below file in Controller Folder CustomNoRouteHandler.php

<?php

namespace SimplifiedMagento\RequestFlow\Controller\Page;

class CustonNoRouteHandler implements \Magento\Framework\App\Router\NoRouteHandlerInterface
{
    public function process(\Magento\Framework\App\RequestInterface $request)
    {
        $request->setRouteName('noroutefound')->setControllerName('page')->setActionName('customnoroute');

        return true;
    }
}

Step-2 My redirect page which should be display while no route found,

<?php

namespace SimplifiedMagento\RequestFlow\Controller\Page;

use Magento\Framework\App\Action\Action;
use Magento\Framework\App\ResponseInterface;

class CustomNoRoute extends Action
{
    public function execute()
    {
        echo "this is our custom 404 page";
    }
}

Step-3 In etc/frontend/di.xml

<?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\Framework\App\Router\NoRouterHandlerList">
        <arguments>
            <argument name="handlerClassList" xsi:type="array">
                <item name="handlerinfo" xsi:type="array">
                    <item name="class" xsi:type="string">SimplifiedMagento\RequestFlow\Controller\Page\CustonNoRouteHandler</item>
                    <item name="sortOrder" xsi:type="string">50</item>
                </item>
            </argument>
        </arguments>
    </type>
</config>

Step-4 In etc/frontend/routes.xml

<?xml version="1.0"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
    <router id="standard">
        <route id="noroutefound" frontName="noroutefound">
            <module name="SimplifiedMagento_RequestFlow" />
        </route>
    </router>
</config>
5
  • what's URL you are run ??? May 19, 2020 at 5:21
  • any wrong url like "domain/abababa", so if no route found than it should redirect to my custom url "domain/noroutefound/page/customnoroute". May 19, 2020 at 5:37
  • if you want to this type prnt.sc/sjfj5o May 19, 2020 at 6:05
  • yes but it redirect me to default 404 page layout. May 19, 2020 at 6:15
  • Step-3 Aurgment name is incorrect handlerClassList it should be handlerClassesList Jun 24, 2021 at 20:37

1 Answer 1

0

I have done the same custom 404 page for one of my extension.

I see a difference of code in Route php file process method.

Your ones is

$request->setRouteName('noroutefound')->setControllerName('page')->setActionName('customnoroute');

While i found in my code is

$request->setModuleName('noroutefound')->setControllerName('page')->setActionName('customnoroute');

Also put di.xml inside etc/di.xml insetad of etc/frontend/di.xml

Try this change once if that work for you.

3
  • i tried your code but it is not working as well. May 19, 2020 at 8:37
  • You should put di.xml code inside etc/di.xml instead of etc/frontend/di.xml and it will work.
    – Yash Shah
    May 19, 2020 at 9:14
  • already tried this but not working. May 19, 2020 at 10:11

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.