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.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | system-path-check-3419355-1.patch | 662 bytes | anthonygray47 |
Issue fork redirect-3419355
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
Comment #2
anthonygray47 commentedComment #3
rhovlandI 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.
Comment #4
rhovlandOk 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/1465changed to/product/1465-a-pretty-nameComment #6
eduardo morales albertiSteps to reproduce:
Comment #8
eduardo morales albertiReady to review, check that the alias is not the same as the source before creating the redirection
Comment #9
eduardo morales albertiAdded also a constraint following the instructions of @rhovland
Comment #10
eduardo morales albertiFailing phpstan and phpcs but not introduced on the MR