Problem/Motivation

Our site uses Pathauto to create aliases for our nodes. Some of our Pathauto patterns for content types rely on where the node is in a menu tree. There are times we will create content and not put it in a menu until it has been approved. This temporarily leaves the system path (/node/[node-id]) the only alias for the content, and once we place the content in the menu, our final alias is created.

Our site settings for redirects are as follows:

  • Automatically create redirects when URL aliases are changed = TRUE

Our site settings for alias update actions are as follows:

  • Create a new alias. Delete the old alias = TRUE

Now, when we finally put our content in the menu, a redirect loop happens since it creates a redirect using the system path.

Proposed resolution

To bypass this specific case, I wrote a patch to check if the $original_path_alias is the $system_path. If this is the case, then do not create the redirect.

I tried going through the current open issues to see if this had already been reported. I couldn't find anything, but if this happens to be a duplicate, please close this issue. Thanks.

CommentFileSizeAuthor
#2 system-path-check-3419355-1.patch662 bytesanthonygray47

Issue fork redirect-3419355

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

anthonygray47 created an issue. See original summary.

anthonygray47’s picture

StatusFileSize
new662 bytes
rhovland’s picture

I am also encountering this on our site. I have pathauto installed. It was added later after a bunch of products were already created with urls such as `/product/2398`. When I go to enable automatic aliases for those products a redirect is automatically created for the path, creating an infinite loop.

While the redirect UI to add a redirect validates these issues and refuses to create aliases that would cause infinite loops it seems it's missing validation when redirects are created programmatically.

A patch to do this validation when redirects are created automatically is needed to prevent this from happening. The currently posted patch does not address this as it only checks for node paths.

rhovland’s picture

Version: 8.x-1.9 » 8.x-1.x-dev
Assigned: anthonygray47 » Unassigned

Ok I have information about how to reproduce this.
If you have automatic redirect creation enabled and have saved an entity with the url alias set to the system path for the entity. Go back and change it to something else. A redirect will be created that results in an infinite redirect loop.

Eg:
Url alias for a product set to /product/1465 changed to /product/1465-a-pretty-name

eduardo morales alberti made their first commit to this issue’s fork.

eduardo morales alberti’s picture

Steps to reproduce:

  • Create a node, for example node/1
  • Create an alias admin/config/search/path/add, with the path and alias /node/1
  • Edit the alias and change it to /a/foo
  • The path alias hook redirect_path_alias_update will create the redirect node/1 => internal:/node/1
  • Visit /node/1 or /a/foo, it will give 503 error, "Redirect loop identified at /node/1 for redirect N"

eduardo morales alberti’s picture

Status: Active » Needs review

Ready to review, check that the alias is not the same as the source before creating the redirection

eduardo morales alberti’s picture

Added also a constraint following the instructions of @rhovland

eduardo morales alberti’s picture

Failing phpstan and phpcs but not introduced on the MR