1. FIX IN ADMIN
After installing the Magento 2 extensions, you may encounter the “Magento 2 404 Error Page Not Found“. Do not worry. That is because of permission in your current session. Follow this guide, we will show you how to solve 404 Error Page Not Found in Magento 2 step by step.
You can easily fix this by resetting role of your administrator permission:
- Step 1: Login to your Magento Admin Panel
- Step 2: Go to System >> Permission >> Role
- Step 3: Choose the “Role name” you want to edit.
- Step 4: Pick “Role Resource” Tab and change “Resource Access” to “All“
2. FIX IN FRONTEND
Magento 2 404 Error Page Not Found is a common error caused by broken links on your Magento site. This may be due to your index management. So how to fix the 404 Magento Not Found Page at the frontend?
- Step 1: Log in to your Magento Admin Panel
- Step 2: Go to System >> Index Management
- Step 3: Click on Select all >> Reindex Data >> Submit
Patiently wait a few minutes to refresh the index
However, there are some cases where you can not fix it. So, consider the third way
3. MAGENTO 2 CREATE CUSTOM 404 PAGE
You can customize the 404 page in Magento. If your site’s visitors are trying to visit a non-existent page, you can display a private message to them, or can suggest a link to another page. 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">
<arguments>
<argument name="handlerClassesList" xsi:type="array">
<item name="default" xsi:type="array">
<item name="class"
xsi:type="string">VendorModuleControllerNoRouteHandler</ite
m>
<item name="sortOrder" xsi:type="string">200</item>
</item>
</argument>
</arguments>
</type>
add this content in above-mentioned controller
<?php
namespace VendorModuleController;
class NoRouteHandler implements MagentoFrameworkAppRouterNoRouteHandlerInterface {
public function process(MagentoFrameworkAppRequestInterface $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.