Override 40x System error pages on Drupal 8 | Drupal 8

Override 40x System error pages on Drupal 8

Submitted by editor on Mon, 02/20/2017 - 16:31
Question

How to override 401, 403 and 404 error pages on Drupal 8 ?

You have several mthodes to override 403 / 404 System pages.

Method 1. Set 403 / 404 pages.

You can set the 403 /404 page on "Basic site settings" page
Admin -> Configuration -> System -> Basic site settings
Path /admin/config/system/site-information

Method 2. Override system 40x Pages (/system/404 ...)

Step 1. Create a custom module (Here : 'mymodule').

Step 2. Create a basic page (Here : \Drupal\mymodule\Controller\MyErrorPage:on404).

Step 3. Add routing.yml file (Here : mymodule.routing.yml).
Example:
mymodule.system.404:
  path: '/system/404'
  defaults:
    _controller: '\Drupal\mymodule\Controller\MyErrorPage:on404'
    _title: 'Page not found - 404'
  requirements:
    _access: 'TRUE'

Tags

Add new comment