Empty page on Réponse 403 - 404

Created on 12 January 2023, almost 2 years ago
Updated 5 August 2024, 3 months ago

Hi, sorry for my bad english

Problem/Motivation

When response code is defined on 301 or 302, it redirect to the correct link.
When Response code is defined on 403 or 404, then i got a blank page, or a page filled with content of response body.

my question is, why not use the 403 - 404 page specified on Basic site settings -> Error pages (/admin/config/system/site-information) when no response body is set ?

Proposed resolution

This code may not be the best, but it works for me.
Be aware that i've set value on page /admin/config/system/site-information for 403 and 404 field.

in file AccessFilterLegacyMiddleware.php function handle(...)

...
if (in_array($code, [301, 302])) {
    return new RedirectResponse($filter->get('parsedResponse')['redirect_url'], $code);
} elseif (empty($filter->get('parsedResponse')['body']) && strcmp($code, 403) == 0 ){
    return new RedirectResponse(\Drupal::config('system.site')->get('page.403'));
} elseif (empty($filter->get('parsedResponse')['body']) && strcmp($code, 404) == 0 ){
    return new RedirectResponse(\Drupal::config('system.site')->get('page.404'));
} else {
    return new Response($filter->get('parsedResponse')['body'], $code);
}
...

thanks for all, and best wishes for the year 2023

Feature request
Status

Closed: works as designed

Version

2.0

Component

User interface

Created by

🇧🇪Belgium SylDanh

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇯🇵Japan hayashi

    > my question is, why not use the 403 - 404 page specified on Basic site settings -> Error pages (/admin/config/system/site-information) when no response body is set ?

    Because it is difficult to display content of 403/404 page configured in site settings.
    You can use 301/302 and redirect url. This results the same as your code.

Production build 0.71.5 2024