Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

Override 40x System error pages on Drupal 8

By editor , 20 February, 2017
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

  • Drupal 8
  • Code
  • Add new comment
Create a simple module for Drupal 8 - Step 2 - Create Simple Page

Comments1

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

David (not verified)

8 years 4 months ago

That doesnt work

Error says the path already exists

  • Reply

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer