Problem/Motivation

This relates to #2821158: Guide users who enter path aliases to use internal paths instead

Redirects are matched against system paths. So a redirect from node/123 also redirects /foo-bar, the alias of that node. Drupal turns /foo-bar into node/123 before it looks for a redirect (inbound path processing).

When the alias is deleted, that stops. The published URL returns a 404 and nothing warns the user.
Deleting the node does the same, because its aliases are deleted with it.

This is usually the point of the redirect: the editor wants /foo-bar (the canonical path) to keep pointing to /somewhere once the node is gone.

Steps to reproduce

  1. Create a node (e.g. /node/123) with the URL alias (e.g. /foo-bar).
  2. Create a redirect from node/123 to /somewhere.
  3. Visit /foo-bar, it redirects to /somewhere.
  4. Delete the /foo-bar alias (or the node).
  5. Visit /foo-bar, it is a 404.

Proposed resolution

When a path alias is deleted, copy the redirect for its system path to the alias path so the published URL then keeps redirecting.
This is opt-in, behind a new setting (off by default).

Remaining tasks

Review.

User interface changes

A checkbox on the redirect settings form, "Keep redirects working when a URL alias is deleted", off by default.

API changes

None.

Data model changes

None.

Issue fork redirect-3620838

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

herved created an issue. See original summary.

herved’s picture

herved’s picture

Issue summary: View changes

herved’s picture

Issue summary: View changes
herved’s picture

Category: Bug report » Feature request

Three choices are not obvious from the diff:

  • When a path alias is deleted, and if there is a pre-existing redirect, it makes a copy. pathAliasInsert() already deletes any redirect that uses a new alias as its source, so if we were to update the existing redirect, it would be lost for good if the alias comes back. Only the copy is deleted, and the original covers the alias again.
  • The copy takes the language of the alias. A language neutral copy would match the alias path in every language prefix.
  • The lookup is a direct hash query. findMatchingRedirect() breaks the deletion in two ways, both covered by tests.

Not copied, same as today: a language neutral alias with a language specific redirect, and a source with a query string.

---

Let me know if this is something you would consider for the module. I can also adapt the approach if needed.

herved’s picture

Status: Active » Needs review