How to add custom error pages in Magento 2?

The question:

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 these pages: 500, 401, 403, and 404. I hope someone can help me.


The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

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 programmatically solution, add the below content in your <root-magent>/app/code/Vendor/Module/etc/di.xml

<type name="MagentoFrameworkAppRouterNoRouteHandlerList">
    <argument name="handlerClassesList" xsi:type="array">
        <item name="default" xsi:type="array">
            <item name="class"
            <item name="sortOrder" xsi:type="string">200</item>

add this content in above mentioned controller

namespace VendorModuleController;
class NoRouteHandler implements MagentoFrameworkAppRouterNoRouteHandlerInterface {

    public function process(MagentoFrameworkAppRequestInterface $request) {
        $moduleName= 'cms';
        $controllerName = 'index';
        $actionName= 'index';

        return true;

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

follow this link to set 401,403,500 page

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment