Switch theme by http status code We have a page that uses several themes, but the 404 pages should all look the same.

So, for all themes except one we need a rule that switches to another theme when the URL does not match any content.

There are ways to choose the theme by the current URL, like using the context module, or implementing a ThemeNegotiatorInterface, and we use them to assign our themes to certain parts of the website.

It seems that the ThemeNegotiatorInterface is not used when delivering a 404 error page.

So, how can we switch the theme according to the http status code?
I've done something similar by implementing the ThemeNegotiatorInterface. In the function that determines which theme should be used, the following code snippet checks for a 404 Page Not Found exception:

$status = \Drupal::requestStack()-&gt;getCurrentRequest()-&gt;attributes-&gt;get('exception');
if ($status &amp;&amp; $status-&gt;getStatusCode() == 404) {
  return 'name_of_the_theme_that_should_handle_404_responses';
}