- 🇬🇧United Kingdom kewesley
We were also running into this issue. The current warning shows the same message regardless of whether the existing path is a system path or a path alias and, in my opinion, I don't think the message is sufficiently clear that the redirect will not take effect if the source path is an existing path alias. It does make sense that the alias gets priority, but is very easy to forget or overlook.
Often, the redirect is being added some time after the alias was originally created, sometimes not by the same person, and because the form still allows the redirect to be created, they assume it will work.
I attach the patch we are using to detect path aliases and show a stronger warning, in case anyone else would also find it useful. I believe it requires at least Drupal 8.9 due to using
\Drupal::service('path_alias.repository')
. Unfortunately, it seems there is no way to query for an alias without also specifying the langcode to check, so there might be a bit more overhead on sites with several languages installed. This patch will also block the redirect from being created if it detects a path alias is being used as the source.If you do need to redirect from one node to another, you can use the system path as the redirect source, even without removing the alias (with or without the patch).