Pass the internal path to the redirect translator

Created on 30 May 2025, about 1 month ago

Problem/Motivation

The Redirect module seems to be designed to work the following way.
- To redirect from an old URL alias, or a non-existing/external path, administrators can create redirects that using that as the source.
- To redirect from a valid route to another, administrators should use the internal path of the route and NOT its URL alias.

This seems to be because you wouldn't have a reason to redirect an active URL alias, you would want to redirect the route/entity completely instead. If the URL alias for that route/entity were to change, the redirect would be lost/not applicable otherwise.

The Redirect module, therefore, passes the URL through the inbound path processor before looking up for redirects, and that converts it to its internal path. Therefore, redirects that use active URL alias are ignored - they are invalid.

This module, however, displays the opposite behavior. If you create a redirect using the URL alias of an entity as its source then that is picked up, while if you create a redirect using the internal path as its source then that is ignored.

This causes confusion for administrators, and opens up the potential for bugs as it has the opposite behavior of the Redirect module.

Steps to reproduce

  • Create a redirect using the URL alias of an entity as its source and observe that it is taken into account in a Drupal frontend.
  • Create a redirect using the internal path as its source and observe that it is ignored in a Drupal frontend.
  • Create a redirect using the URL alias of an entity as its source and observe that it is taken into account in the Decoupled Router response.
  • Create a redirect using the internal path as its source and observe that it is ignored in the Decoupled Router response.

Proposed resolution

Add an event subscriber that processes the path before the other path translators are executed.

Remaining tasks

Agree on the issue and the approach.

API changes

I guess this is a behavioral change that may affect some applications. Administrators on existing sites may have been creating redirects the wrong way as a result of that behavior and making the propose change - while correcting the behavior - might cause unexpected results on existing applications in such cases.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇵🇪Peru krystalcode

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

Comments & Activities

  • Issue created by @krystalcode
  • 🇵🇪Peru krystalcode

    Here is a first take on this - moving the issue to review so that the module maintainers can respond on the approach before taking this further.

    Having try to make some customizations and fix a number of bugs, I have found that the code could be better structured and make things more easily alterable/extensible. I have therefore started moving some functionality related to path processing and route matching to separate classes. The event class and router translator should be later updated to not have to compute the same things twice when no redirects are involved.

    This patch is incomplete and while I have tested it for my use case (together a number of other patches and bug fixes/customizations) it might introduce bugs for other applications - so, don't use it yet. It's just a starting point to see if that direction works for others or not.

Production build 0.71.5 2024