When getting a 403 error, Drupal is not redirecting to the URL configured in the Site Information settings. Instead, it keeps the URL in the address bar of the browser, uses the page template (page--XYZ.html.twig) for that same URL and only the content of the page ({{ page.content }}) reflects the URL I've configured in the site information settings.

Does anyone know how to get a full redirect to the configured 403 page?

  • 2
    I wouldn't recommend this approach, this is not how HTTP works. You would have to send an 301 or 302 first to change the URL, and then respond with an 403 on the target page. You would mark the wrong page as "access denied". – Hudri Oct 22 at 5:50
  • 1
    There are special cases where it makes sense, for example to redirect to the login page. See drupal.stackexchange.com/questions/165884/… – 4k4 Oct 22 at 6:24
  • 2
    As you have discovered, the path specified in those settings is not treated as the target of a redirect, and thus your question is framed slightly wrongly. The question you want is "how to redirect to <page xxx> on access denied", where page xxx will have to be configured by some other means. One possible answer is linked in the comment from @4k4. – Alfred Armstrong Oct 22 at 9:00

Well, by now I just found that my question is technically wrong. Drupal is not supposed to do any redirect (HTTP 301/302) on access denied errors (HTTP 403). This is not how HTTP works (as mentioned by @Hudri in the comments).

On an access denied error, Drupal replaces the actual page content with the one from the "Default 403 (access denied) page" site setting. The URL being accessed is valid. It's just that we don't have the permission to see its contents.

I just figured what I was actually wanting to do, was telling Drupal not to use that page's regular template file (page--xyz.html.twig) on the case of an HTTP 403 error, but instead, to use a different one.

Found useful instructions on how to theme HTTP error pages here: https://www.axelerant.com/resources/team-blog/customizing-http-error-pages-in-drupal-8

  • The theme suggestion page--403.html.twig, for which you have linked the code in the blog post, will be available in Drupal 8.8 out-of-the-box, see drupal.org/node/2960810 – 4k4 Oct 22 at 13:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.