3

I'm having a problem since I'm new to Magento.

how can I create a custom error pages in my magento 2 site. for example this pages: 500, 401, 403, and 404. I hope someone can help me.

Thanks

6

you can customize (404) page from admin

Content->Pages->404 Not Found->Edit->content

here you can change whatever content you need.

If you look programatically solution, add the below content in your <root-magent>/app/code/Vendor/Module/etc/di.xml

<type name="Magento\Framework\App\Router\NoRouteHandlerList">
<arguments>
    <argument name="handlerClassesList" xsi:type="array">
        <item name="default" xsi:type="array">
            <item name="class"
            xsi:type="string">Vendor\Module\Controller\NoRouteHandler</ite
            m>
            <item name="sortOrder" xsi:type="string">200</item>
        </item>
    </argument>
</arguments>
</type>

add this content in above mentioned controller

<?php
namespace Vendor\Module\Controller;
class NoRouteHandler implements \Magento\Framework\App\Router\NoRouteHandlerInterface {

    public function process(\Magento\Framework\App\RequestInterface $request) {
        $moduleName= 'cms';
        $controllerName = 'index';
        $actionName= 'index';

        $request
        ->setModuleName($moduleName)
        ->setControllerName($controllerName)
        ->setActionName($actionName);
        return true;
    }
}

In this controller you can set whatever module/controler/actionname for 404 page.

follow this link to set 401,403,500 page

  • Hi bro thanks for this wonderful answer!!! Thank you for helping me :) – MazeStricks Sep 2 '16 at 8:47

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.