Needs work
Project:
Redirect
Version:
8.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
19 May 2017 at 07:05 UTC
Updated:
13 Oct 2026 at 19:31 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
ameymudras commentedComment #3
ameymudras commentedComment #4
berdirThanks, I think there's an existing issue about this already as well.
Not sure about having that logic in preSave(), but lets see.
This will need tests, though.
Comment #5
ameymudras commentedThanks, could you please provide the existing issue link?
Comment #6
berdir#2821158: Guide users who enter path aliases to use internal paths instead is the related issue.
Comment #7
wim leersComment #8
wim leersFor #4.
Comment #9
enzipher commentedI ran into this issue as well, and here is an alternative patch where the path check is done in the
generateHashfunction. I'm not sure if this has a performance impact or not, but it seems better to handle it there.Comment #11
jmuzz commented#9 worked for me, thank you!
It also applied cleanly for me... Wonder why the testbot couldn't do it.
Comment #12
berdirI don't think that is the right place. That means we still store the alias, and while the hash might match, the actual stored source path will not, which in my opinion is confusing. We should do this on the user input and store the de-aliased source path.
Comment #13
prashant.cfor #2 i tried to use Dpendency Injection for Path Alias Manager Service but somehow it is throwing following error
Fatal error: Declaration of Drupal\redirect\Entity\Redirect::create() must be compatible with Drupal\Core\Entity\EntityInterface::create(array $values = Array) in /var/www/html/drupal/modules/redirect/src/Entity/Redirect.php on line 0Can someone please let me know what could be the cause of this ?
Comment #14
berdirEntity classes don't support dependency injection. Best you can do is add a method that wraps the Drupal::service() call.
Comment #15
gsines commentedUsing #9 fixed the issue but if the URL path changes in a content type (i.e. changing a title with path auto enabled) it is not reflected back to the redirect and presents as a 503 error "Service unavailable" for the redirect to old URL and using the new path URL.
If you go into the redirect of that item and save it, the redirect and the new path work again.
Comment #16
miro_dietikerLots of side effects here..
If the user enters the alias source path and then we store the unaliased path, we have a dependency to the alias.
Deleting the alias (without awareness about the redirect) will break the redirect.
This is confusing with the mindset that obsolete aliases convert to redirect. People will expect that they can delete the alias if a redirect exists. We would need better UI integration like warning a user when editing / deleting an alias that a redirect depends to it.
Storing the alias source path and matching on the hash of the unaliased path could be OK as long as invalidation works. If the alias is deleted, we need to update the matching to the source path.
Currently a redirect is deleted if an alias with the same path is created. IMHO this should only happen if the target is the same. If such a redirect would still exist when an alias is created, we need to check if a redirect needs update. If the target is different i would consider the source path as reserved.
On the opposite - the user should be warned if trying to create a redirect for an URL with an alias. In most cases this is an accidental clash.
(More variations could happen with varying language settings - some for all languages - some only for a specific language.)
Comment #17
ravi shankar karnati commentedHi @ameymudras - #2 patch is not able to apply with the redirect module version 1.3
Comment #18
ravi shankar karnati commentedRegarding redirect not working for URL alias, please find the patch for redirect module with version 8.x-1.3 and do the review.
Comment #19
phil_bHi,
in our current project we faced the same problem.
Patch #18 could solve the problem for us
Thank you
Comment #20
Anonymous (not verified) commented#18 seems to work for me.
I did come across two warnings when applying the patch. Seems to work though but not sure if it's worth kicking into RTBC before the warnings are sorted.
Comment #21
maximpodorov commentedPatch #18 is reworked, reformatted and rerolled.
Comment #23
maximpodorov commentedLanguage parameter is added to path alias processing.
Comment #24
g.weston commentedHi maximpodorov,
Just a heads up as I tried patch #23 today and it didn't work. The redirect module still ignored any redirects created when using an alias.
Comment #25
miro_dietiker@g.weston are you aware that this needs a resave of each related alias for the patch to take effect?
Comment #26
awolfey commentedI find that the patch does not work when there are multiple redirects from a path, because the patch creates them the same hash from any alias for a node.
Example:
my-node and my-node-with-a-new-alias will have the same hash. The redirect from the old to the new alias is created automatically by Redirect.
If I visit my-node or my-node-with-a-new-alias I get a redirect loop because they both have the same hash
If I try to update the alias again there's an integrity constraint violation because the hash is already in the database.
Comment #27
sonu.raj.chauhan commentedUpdated the #23 patch to support und langcode. Path alias manager was returning false results when langcode und was passed to it.
Comment #28
sonu.raj.chauhan commentedComment #29
sonu.raj.chauhan commentedComment #30
sonu.raj.chauhan commentedComment #31
SaraKlasson commentedHi! Patch #29 works for me after I re-generated all URL aliases.
It also worked if I instead of regenerating URL aliases, I re-saved the specific redirect after applying the patch.
Comment #32
berdirThis needs work for tests and coding standards (spaces, double quotes), it also shouldn't hardcode 'und' but use the constant for it from LanguageInterface.
Comment #33
valthebaldI've added also the case when broken URL alias already exists, but leads to infinite redirect lopop
Comment #34
feng-shui commentedThis is just a re-roll of 33 to clean up the coding standards, will take a look at why the tests are failing today.
Comment #35
feng-shui commentedAdding this to get it tested, should have resolved one of the failing tests, expecting some failures.
The major change here is to get
RedirectRepository::findMatchingRedirect();to check if the path is an alias and if it is, drop in another hash to look for, one that matches the alias's source (multiple hashes are already searched for, so this seems like a good place to put it).At that point, we can switch things like searching for duplicates in
RedirectForm::validateForm();to use the repository rather than using `Drupal::entityManager` and having to check for an alias on the fly there.Although I haven't looked at it yet, I'm guessing we'll still need a way to re-save all redirects to update hashes. On some sites, this is going to be a fairly large process (current site I'm working on has 4,000+). Not sure if we can handle this in an update hook or not, something I still need to look at.
Comment #36
valthebald@Feng-Shui well, we have batch API for that, node.module and taxonomy.module have performed schema updates that way.
Comment #37
feng-shui commentedUpdated patch to resolve the last failing test, also includes an update hook to re-save all redirects to update their hashes.
Comment #38
feng-shui commentedComment #39
feng-shui commentedPrevious patch had an issue with the update hook.
Comment #40
feng-shui commentedAdd test to cover off the ability create a redirect from a path's alias and then find the redirect using the repository by searching for the path's source. Removing the
Needs teststag for now.Going to leave this here now until it gets a review.
Comment #41
Fastmover commentedHow about checking the relative url besides just the node/id? I had an instance of redirect not working because there was an unpublished node with the same url, and it was grabbing that node id instead of the actual url.
Comment #42
feng-shui commentedI think some input from @Berdir as to the preferred approach would be good, comments in #32 suggested the patch in #40 was the direction to move in, but the above would work this in that specific instance. Displaying the patch in #40 again, it covers off the comments in #32.
Comment #43
valthebaldI think the patch in #40 looks good, 2 code style comments though:
would it make sense to store path.alias_manager in a (static?) class variable?
I suggest to inject the service here, instead of using \Drupal call
Comment #44
feng-shui commented@valthebald thanks for taking a look at the patch.
In both cases I've used
\Drupal(and helper classes such asLanguage::over injection as that seems to be inline with the code style of the rest of the module. Happy to swap these out for service injection though if the maintainer would prefer.I've got a colleague taking a look at this too tomorrow, we're going to run the update function on our site with the 3k+ redirects and make sure that works as expected.
Also just going to hide a few of the previous patches here.
Comment #45
feng-shui commentedFixed two issues:
1: redirect count in install hook was off by one which meant that if there was only one redirect the update hook wouldn't run
2: when checking for an alias in the preSave hook, check for an alias using the redirect's language and "not specified" (Language::LANGCODE_NOT_SPECIFIED) - this was preventing some redirects from getting updated hashes.
Comment #46
feng-shui commentedComment #47
feng-shui commentedFollowing some additional testing by a colleague, an additional alias language check needs to be done int he preSave function. Need to check for aliases using the redirect's language, language not specified and then the path systems default language value - this isn't overly elegant, but there's no way to determine the correct language to use to try and find aliases.
Comment #48
berdirI'm concerned a bit about this update function.
I know there are sites out there with tens/hundreds of thousands of redirects and probably more. I'm testing it on a site with 34k, the update takes 3m30s , which isn't that long, but I'
There are some things we should do. One, this should be a post update function, because we're using the entity api. Then, instead of saving all redirects, we could check if the new resave logic actually makes a difference, because for 99% of the existing redirects, it shouldn't. Last, instead of the hardcoded 20 limit, we can use Settings::get('entity_update_batch_size', 50), especially considering we won't resave most of the redirects. Large sites with a lot of resources can set that higher to process updates more quickly.
The alternative would be to not include a forced update at all, I would be OK with that I think. But I think with those changes, it should be acceptable also on very large sites.
As a phpunit test, it will stop on the first failed assertion, so I'd just write this as two assertions, first assertInstanceOf, and then that it is the same redirect.
Comment #49
feng-shui commentedChanges as requested.
Comment #50
Wakuiy commentedPatch #49 did not fix the issue in my case.
I don't think the post_update applied correctly, as the hash stored in the redirects table did not change, and is still generated using the alias originally input.
Looking at the preSave, I think there is a mistake in the conditional regarding language -
if ($path === $this->redirect_source->path)andelseif ($path === $this->redirect_source->path). Is this supposed to be a separate if statement?---
In my case,
$redirect_languageis 'und', however getPathByAlias returns the input value when using either$redirect_languageorLanguage::LANGCODE_NOT_SPECIFIED. It correctly returns the node path when no language parameter is provided, therefore the final assignation would have worked out.Thanks
Comment #51
feng-shui commentedThanks for testing.
The conditional is correct. The issue here is that there's no way to determine what language may resolve the alias to a source. So while it's a bit ugly, we check for the three options we have. Firstly using the redirect's language, and if that doesn't change the path (ie it didn't resolve the alias to a source) we check with
LANGCODE_NOT_SPECIFIEDand if that doesn't change the path, we check with no language (which uses the path system's default language which isNULL).Based on what you've said, if the first two returned the original path passed to
getPathByAlias()unmodified then theelseifshould have been satisfied and you should have had the alias resolved to a source on the third go. Do you know why that didn't happen, sounds like it should have?Comment #52
Wakuiy commentedHm, both conditionals check for the exact same thing
$path === $this->redirect_source->path, so the else if statement will never be hit, even on multiple iterations.Comment #53
feng-shui commentedAhhh, my bad you're saying that the
elseifshould be anif. Yes, that's correct and that's prob why your hashes didn't get updated, I must have made a typo when I created the above patch, see if this one works.Comment #55
bkosborneSeveral of my colleagues and I have been very confused by this behavior, especially because the Drupal 7 version of the module does not behave like this. In Drupal 7, when you add a redirect with a source of an existing path alias, the redirect module automatically converts it to the system path on save. In Drupal 8, that does not happen (thus the reason for this issue). I think some of the points brought up in this issue are valid, but I wanted to express this is a big WTF at the moment :(
Comment #56
feng-shui commentedLooks like an additional cache clear is needed in the failing test.
Comment #57
rahulrasgon commentedPlease review the patch.
Comment #59
feng-shui commentedI don't have the time to keep working on this issue right at the moment, we're using a workaround of removing aliases that we want to redirect. I think this patch is pretty close (not sure why the latest one didn't apply, it did locally). Would be good if someone else can pick this up for a while, I think it's pretty close.
Comment #60
kuldeep k commented#56 patch worked for me. post_update is running correctly in that. Thanks for the help.
Comment #61
herved commentedThe last patch in #57 contains issues compared to #56.
Should be $sandbox['progress']++;
Need newline here.
But what concerns me much more is that having the logic in the presave seems to cause infinite redirections as the tests shows.
I recently inherited a project with patch #53 and I'm having such infinite redirects when updating the title of nodes.
Here's the scenario:
1. Make sure you have "Automatically create redirects when URL aliases are changed." enabled at admin/config/search/redirect/settings
1. Edit an existing node and change its title
2. A redirect gets created but the hash is now generated from the system path (e.g: node/123) and its language, while the redirect source path is the old alias
> problem 1: the hash is not in sync anymore with the source path stored in DB. Loosing consistency.
3. When viewing the node we now get an infinite redirect because a redirect is found in
\Drupal\redirect\EventSubscriber\RedirectRequestSubscriber::onKernelRequestCheckRedirect.This is because it will query the redirect table with a hash generated from the current system path (e.g: node/123) and the current language.
One way I can think of to solve this issue is to convert the given path alias to its system path on form submit when creating a redirect manually. But even then, I believe it could break existing sites if some of their redirects get re-saved.
I'm thinking of the following scenario:
Status before patch:
- A redirect exists from "test" to "internal:/node/123"
- At this point, no aliases exist for "test" path itself, without the redirect it leads to a 404
- At some point, the "test" path now matches an alias of a new node: node/789
Status after patch:
- If we re-save the old redirect, node/789 redirects to node/123 > not good
Comment #62
micnap commentedI have not dug in to figure out why but patch #57 causes an infinite loop during database updates on a D8.7.9 site I'm working on. If I remove the patch, the updb goes fine. Apply the patch and run 'drush updb' and I get "[notice] All redirects have been re-saved to update their hashes." written to the console infinitely. "
Comment #63
herved commentedPerhaps we could use another approach:
Change the form for the source path and use an entity_autocomplete form element (or link widget) allowing users to select nodes.
Then we would store a node path in the same format as link fields, e.g:
entity:node/42We would need to change slightly the the detection in
\Drupal\redirect\EventSubscriber\RedirectRequestSubscriber::onKernelRequestCheckRedirectto add "entity:" if we're on a node or entity path.This wouldn't require any risky or long updates.
Comment #64
micnap commentedWas able to troubleshoot the infinite loop in patch #57. Looks like it was just a ++ left off of a counter.
Comment #65
micnap commentedComment #66
callinmullaney commentedPatch #64 seems to have resolved the issue for me. We were able to create new redirects with path aliases.
Comment #67
herved commentedThe approach here is still problematic IMHO as I explained in #61.
Please have a look at my comment.
The approach I suggested in #63 is much safer I believe but we'd need more feedback from the maintainers and you all before anyone starts working on it.
Comment #68
berdirComment #69
lolandese commentedReview of #64 patch
I am seeing in the last (#64) and some preceding patches:
Using the same conditional twice (($path === $this->redirect_source->path)) results in always the last being used. Both defining the same variable
$pathwill result in always the second one being used.In #50 the same was already mentioned as well but there the second conditional was an
elseif. In that case, the first conditional is always used, so it seems incorrect in both cases.Can someone clarify?
Furthermore, the patch does not apply:
Reroll needed.
Comment #70
lolandese commentedReroll of #64 patch that applies cleanly to the 1.5 version and the current dev.
Be aware, as stated in #69, that is is still using the same conditional twice (($path === $this->redirect_source->path)) resulting in always the last conditional being used. We need to find the correct logic to define the variable $path.
Furthermore, note that you need to resave each related alias redirect for the patch to take effect.
Comment #71
smustgrave commentedQuestion what is the purpose of
Why wouldn't we use the language of the redirect itself?
Comment #72
lowfidelityThanks for your work so far!
I applied #70 to a D8.8.1 site, on both 1.5 and 1.x-dev versions of the module. Patches applied without an error, but I still receive a page not found error, when trying to open any of the redirects (with path aliases). I tried resaving and recreating redirects, with certain languages and language neutral, and did a cache rebuild but without no luck.
Is there any further step required to get the existing redirects working again with patch from #70?
As a temporary and very lame workaround, I added all redirects to the .htaccess file or the apache config for the vhost.
Thanks a lot!
Comment #73
lolandese commentedTrying to replicate your issue (#72) opening a sandbox, with the patch applied at https://simplytest.me/project/redirect/8.x-1.x?patch[]=https://www.drupa...
Steps
Going one step further:
@paper boy
Can you give the steps you did on your project, to try and replicate the issue you have on the sandbox?
Thanks.
Comment #74
dabblela commentedI also had intermittent issues that i tracked down to this code (noted in #71):
The scenario is a redirect with no language (und) that targets a particular alias, but the alias only exists for true language(s). In my setup, AliasManager returns the path of the front page. That path is then used to generate the hash:
Then when the redirect lookup occurs in the RequestSubscriber, the hash is wrong. In my testing, the fix was to use the redirect language for the lookup but I'm also curious what the reasoning behind testing other languages besides the redirect language.
Comment #75
smustgrave commentedI could way off with my idea here. But should we only check the language if the language module is enabled? For one of our sites it is not even an option so we would expect the default site language to be used. Again I could be way off.
Comment #76
enriquelacoma commentedI tested the last patch and got some weird results, i did this:
Comment #77
enriquelacoma commentedI updated the test to fix some problems with path alias activation.
Comment #78
enriquelacoma commentedThe previous patch didn't apply, retest with a new version.
Comment #79
enriquelacoma commentedI updated last patch to fix some testing errors related to the use of language on the operations.
Comment #80
enriquelacoma commentedI updated some test to use the current language, in line alias language
Comment #81
jweedman commentedFirst off, thanks for all the work on this - great timing for me as I'm running into the same issue. Tested patch from #80, unfortunately failed with the following log from a dry-run:
Not sure it's incredibly helpful logs, but thought I'd pass along in case others see the same.
Comment #82
smustgrave commentedPulled the latest version of the dev version and applied the patch from #80 with no issue.
Ran these scenarios too.
1. With the language module disabled I created 2 nodes. /page1 and /page2
2. Created a redirect with the alias /page1 to go to my second node
3. This worked.
1. With the language module enabled. Translated the first node and gave it the same alias. /es/page1
2. Created a redirect for spanish for /page1 to the second node.
3 I was still able to get to my english /page1 node
4. When I go to the spanish page I'm successfully redirected to my second node
5. This worked as expected.
Comment #83
herved commentedThe fact that the hash gets generated always from the source path (e.g: node/2) in
\Drupal\redirect\Entity\Redirect::preSavewhile theredirect_source__pathin the database contains the alias is not ok IMO (as I mentioned in #61) as it makes the hash generation inconsistent.Also, as a result, the redirection works if you keep the node but if you delete it it doesn't work anymore.
Instead of changing the presave, I believe we should change the detection that happens in
\Drupal\redirect\EventSubscriber\RedirectRequestSubscriber::onKernelRequestCheckRedirectto include the current source path AND alias.This will keep the hash generation and what's in db consistent, and it will work even if you delete the node.
But this requires almost a complete rewrite of the patch.
Here is a draft of what I have in mind.
Though I'm not sure the test will pass.. let's see.
In any case, tests need to be provided to ensure the correct behavior of this added functionality.
Comment #84
herved commentedSeems like tests are passing.
Feedback on this approach are most welcome and appreciated.
Comment #85
mgam737 commentedWe had the same issue, i.e. new redirects with sources using alias paths were not working. The 83.patch seems to have redirects functional again.
One question: since the old redirects seem to work, do we need to run any db updates, as mentioned earlier in this thread?
thx,
Mohsen
Comment #86
enriquelacoma commentedI tested patch #83 and existing alias will continue to work after the update.
If we have a node alias with a redirection, for example redirect-test --> home and
we change the alias of the node, for example to redirect-test-2, the alias redirect-test will
redirect and redirect-test-2 will not.
Comment #87
herved commented@mgam737 which patch did you use?
If you used one of the patches before #70, you'll have to "undo" the update, which I did on the site I'm working on.
Here's what I did: https://gist.github.com/vever001/4f71e8b8c38797f73d68db2f5410bc92
Comment #88
smustgrave commentedDid some testing with the patch from #83
Ran these scenarios.
1. With the language module disabled I created 2 nodes. /page1 and /page2
2. Created a redirect with the alias /page1 to go to my second node
3. This worked.
1. With the language module enabled. Translated the first node and gave it the same alias. /es/page1
2. Created a redirect for spanish for /page1 to the second node.
3 I was still able to get to my english /page1 node
4. When I go to the spanish page I'm successfully redirected to my second node
5. This worked as expected.
Comment #89
enriquelacoma commentedI updated patch #83 to fix some coding standards and keep redirections when changing the alias of the of an entity.
Edit: I removed the patch because it contained errors.
Comment #90
enriquelacoma commentedComment #91
enriquelacoma commentedI updated patch #83 to keep redirections when changing the alias of the of an entity.
Comment #92
enriquelacoma commentedI updated patch #83 to keep redirections when changing the alias of the of an entity.
Comment #93
enriquelacoma commentedUse the method createDuplicate to create the new redirection when changing an alias.
Comment #94
herved commented@enriquelacoma, please always provide an interdiff so we can see what has changed.
The update of
redirect_path_alias_update()looks good to me but some other changes are not.No need to change file permissions
Those are not needed I believe.
I'm recreating a new patch with an interdiff from #83 so it's more clear which contains:
1. Update
redirect_path_alias_update()to maintain redirections when updating the alias of of an entity (approach from #91/93)2. Fix some coding standards
3. Update RedirectRequestSubscriberTest::callOnKernelRequestCheckRedirect to better match the current code in 1.x
Tests still need to be provided to ensure the correct behavior of this added functionality, so leaving as needs work.
Comment #95
vidorado commentedI needed the patch to apply cleanly to 1.5 version, so i modified the patch in #70
I had to remove some lines in Redirect's preSave() in order to make the hash calculation from alias, not from source
I'm sure that i'm missing something... there must be a good reason to calculate hashes from source (i.e: node/xxx) but my way, calculating them from path_alias, I can have multiple path alias redirects for the same destination node, and it makes sense to me searching the redirect by the path alias and not by.... i don't know exactly what. I don't understand the purpose of passing the alias to alias_manager in Redirect's preSave()
I have run unit and kernel tests and everything seems to be ok.
PS. - I don't show the file because i don't want to interfere in dev's workline...
Comment #96
herved commented@vidorado
Looking at your patch #95, I don't understand how you can have an alias at this point in:
The
$source_pathwe get as argument is passed through the inbound processor in\Drupal\redirect\EventSubscriber\RedirectRequestSubscriber::onKernelRequestCheckRedirectso it is a source path, it can't be an alias:$path = $this->pathProcessor->processInbound($request->getPathInfo(), $request);Unless the path doesn't have a source (e.g: node was deleted). Is that your scenario?
But then this means that you can't create a redirect for an existing node.
Patch #94 doesn't have this issue.
Comment #97
vidorado commented@herved
I supposed that
$path = $this->pathProcessor->processInbound($request->getPathInfo(), $request);simply removed language prefix and things like that, and what what we finally have in$pathis basically the url after the host and port.When we try to find a matching redirect in
onKernelRequestCheckRedirect()with$redirect = $this->redirectRepository->findMatchingRedirect($path, $request_query, $this->languageManager->getCurrentLanguage()->getId());We are passing this path through path.alias_manager service, you are right...I should remove this piece of code too if I want to honor my approach, and hash by alias, not by path. As you correctly say, this is working because there is not an existing alias for the redirect sources. If it would exist, my code won't not work. ¿I am right?
I attach a subset of the last rows in my redirect table, for illustration purposes.
Comment #98
vidorado commentedI confirm that with patch in #95 redirections weren't being made for existing aliases.
I have had to correct the path inbound processing in
RedirectRequestSubscriberin some.... "quick and dirty" way using Reflection to skip the PathProcessorAlias. The problem with reflection (apart from dirtiness) is performance, but since this is only used once per request, i think is negligible.Now it works for multiple redirect source aliases redirecting to the same node, and even for existing path aliases
Comment #99
enriquelacoma commentedPatch #94 keeps redirections on nodes when changing alias. Also, when the node is deleted, the redirections of the aliases are kept. I added UI and UILanguage test for both cases.
Comment #100
vidorado commentedYes @enriquelacoma, that's what i guessed,
The normal approach from Redirect module is to make redirections **between nodes** whatever alias they have. But now that we are allowing to redirect from alias to node... that looses some sense, I think.
However, we are talking about different patches. Mine applies to version 1.5 and is based on #70. There could have been several improvements since #70, so don't bother too much. Sure that patch in #94 and yours in #99 are a good approach and better than #98, but i needed to patch against 1.5 version! :)
Comment #101
enriquelacoma commentedThere was an error in the test of patch #99, i updated the test in this patch
Comment #102
herved commentedThanks for this @enriquelacoma.
Though I find these tests are a bit hard to understand and read.
If you agree, here's a more simple approach, based on your work.
Comment #103
herved commentedI know this is a already a long thread but allow me to take a step back and re-assess here.
Problem/Motivation
The main issue here is to allow redirections for path aliases.
The code ATM in redirect only checks for the source/system paths (and not aliases) when trying to find redirects.
See https://git.drupalcode.org/project/redirect/-/blob/8.x-1.x/src/EventSubs...
So:
- if we have a node with ID 123 and alias "test-node",
- and we create a redirect from "test-node" to "/destination"
-> http://site.com/node/123 will redirect but not http://site.com/test-node
Proposed resolution
There are 3 proposed solutions so far:
1. #1 to #80: Always generate the hash from the source path in
\Drupal\redirect\Entity\Redirect::preSaveCons:
- it alters the hash generation, hashes are not always in sync anymore with the
redirect_source__pathin DB, so we loose consistency.- on node/path update it can create infinite redirections as I explained in #61.
A workaround? for those infinite redirections has been added to patch #70.
- validations are skipped (like check for duplicates), see
\Drupal\redirect\Form\RedirectForm::validateForm- on node/path delete: redirections won't work anymore
2. #83 to #102: Change the detection in
\Drupal\redirect\EventSubscriber\RedirectRequestSubscriber::onKernelRequestCheckRedirectto include the current source path AND alias.Pros:
- no change to the hash generation, keeping it consistent in db
- validation still runs in the form
Cons:
- big changes to the detection needed to match multiple paths (current source and alias)
- which also impacts performance
- can clash if we have 2 redirections with same source paths but different destinations:
- 1 with
redirect_source__path"node/123"- 1 with
redirect_source__path"test-node"- on node/path delete and update: see scenarios below
3. (NEW) Convert aliases to source paths in the redirect creation form, during the ajax callback. And act on path alias deletions.
This is a 3rd possible solution.
We convert aliases to system paths in the redirect creation form, during the ajax callback.
For the node deletion problem:
- when a path alias is deleted,
- and a redirect for the source of the path alias exists
- if the existing redirect language matches the path alias language being deleted, we update the redirect source to the path alias url
- else if the existing redirect language == "und", we duplicate the redirect and set the redirect source and language according to the path alias being deleted.
Pros:
- Relatively simple to implement
- no change to the hash generation, keeping it consistent in db
- no change to the redirect detection
- validation still runs in the form
Cons:
- ?
To summarize I'd go with option 3 in the end.
I'll post a patch soon, please let me know if I'm missing anything or if some of my analysis is flawed.
Thank you
Comment #104
herved commentedHere is the 3rd approach, without tests.
Comment #105
neslee canil pintoComment #106
smustgrave commentedTested the page in #104
Created /page1 and setup the redirect to go from that page to /page2 on any language. Worked as expected.
Updated the redirect to only be English. Made a translation of /page1 (es/page1) and it displayed the translation page while redirecting /page1. Worked as expected.
Couldn't think of any other scenario but if there I don't mind helping test.
Comment #107
berdirThanks everyone for working on this, that is a huge issue. It would help a lot to have an updated issue summary that .. summarizes all those comments and explains what is exactly being done now.
Also, I fear we need test coverage for the use cases this fixes. For example with a new method on \Drupal\Tests\redirect\Kernel\RedirectAPITest that creates redirects on aliases and ensures they work as expected.
Comment #108
herved commentedHello @Berdir,
I summarized the different approaches in #103, and in the end decided to go for the 3rd approach which is to "convert aliases to source paths in the redirect creation form, during the ajax callback. And act on path alias deletions".
And I'd like yours and others opinion on the chosen approach.
A variant of this 3rd approach could be to make the source path behave like a link field, where we would start typing the title and then select the node from the auto-completion, but there are some caveats as this field is already quite specific.
Comment #109
wesleymusgrove commentedHi @herved
I appreciate your work on this because I'm dealing with this issue as I'm migrating tens of thousands of redirects from a D7 site to a D8 site.
I'm curious if your 3rd approach using the Ajax callback in #103 will work for this use case?
I am using this module https://www.drupal.org/project/path_redirect_import to import the redirects from a CSV file. Since the system "node/123" paths do not match between the old D7 and new D8 site, I can only import the the CSV in "pretty/old-url" -> "pretty/new-url" URL alias format.
However this was when I discovered this bug because none of these imported URL alias redirects actually work because they were not imported using their system "node/123" path.
In fact they cannot be imported using their system "node/123" path because a lot of these URL aliases no longer have corresponding nodes on the the D8 site. They are either a URL alias that existed once upon a time on D7 -or- a dynamic programmatically generated node displayed upon a specific URL alias request that isn't tied to an actual content node.
In D7 this module would let me create redirects for URL aliases that weren't tied to actual nodes and the redirects would still work. Is your Ajax callback method going to enforce that the source URL alias provided in the form must have a corresponding "node/123" that actually exists? Or can the the URL alias redirect stand on its own without trying to be converted to a "node/123" system path during the Ajax callback?
Thanks!
Comment #110
lowfidelityI applied #104 on a 8.8.6 site with redirect:1.6.0 and redirect:1.x-dev. The patch applies successfully but new or existing redirects still end up on the 404 page.
I upgraded from redirect:1.5.0 using composer and applied the patch from #104. Are there any further steps required?
Thank you!
Comment #111
malte.koelle commentedI am not quite sure if I understood the issue right. But what I tried is:
- Create a node with a path alias. (For example: '/some-alias')
- Create a second node without a path alias.
- Create a redirect from the path alias to the URL from the second node. (From '/some-alias' to '/node/2')
When I create this redirect and go on '/some-alias' the redirect to '/node/2' does not work for me with patch #104.
I'm not sure if I missed something. Anyways I created a simple test to cover this scenario, which fails.
The test might need some more work but I would appreciate any feedback.
BR
Comment #113
Mihai Firoiu commentedPatch #104 works well. For newcomers to the issue, please keep in mind the language from which you are adding the redirect from. For example, if you want to add a redirect for a 'de' node, the language in the add redirect form URL must also be 'de'.
That is what
getPathByAliasis looking at. Otherwise, the source_path to system_path conversion will not trigger.I've also added a change to the order of the warnings. Since we always convert to the system path, the URL alias setup warning always triggers as well, which can confuse users as they have already set up the URL alias.
One small caveat remaining would be, I believe - in the future, when one wants to search for a past redirect, it won't be possible to find it based on the URL alias anymore but only by the system path. Regardless, it's nothing major I think.
I would appreciate any feedback on this change.
Comment #114
damontgomery commentedI'm having issues with #104 for multilingual aliases.
Example:
"und" language alias, `my-page` is converted to `node/123`. The redirect does work.
"es-es" language alias, `es-es/my-spanish-page` is NOT converted to `node/456`. The redirect seems to be displayed correctly, but gives a 404.
I was working on some similar functionality and I think the parsing of aliases needs more work here. However, should we try to select the language for the user if they use a language alias? If not, the alias will not work unless the user manually selects the language. For now, we could provide a notice when this needs to occur.
Here is a service I created to parse aliases that we might be able to use parts from. In particular, the `getNodeIdFromAlias` logic should probably be generalized, but it shows how language specific and "und" languages are handled by the Alias Manager.
Comment #115
damontgomery commentedHere is my attempt (without tests) for language support. Based on #104.
If a language is detected in an alias, like `es-es/my-page`, then the language portion is removed so the path can be converted into an alias. A notice is then displayed telling the user to select the language.
I couldn't figure out how to update the language field from this widget since changing the form state doesn't seem to do anything.
Comment #116
damontgomery commentedSorry for the spam, I remember there was a request for tests, so I'm moving this back to "Needs work". Still hopeful this helps move things forward. :)
Comment #117
tomrogHey, I will also add my input here. I was having problems with redirect loop after node is removed from the book. We have alias pattern for each book's node and when node was removed from the booking, the old url redirect (that contained book id) wasn't working. First of all I tried commenting out the part of RedirectRepository.php :
throw new RedirectLoopException('/' . $source_path, $rid);and returning NULL instead. It worked.
But then I found this topic and solution from #9 worked in this specific bug case (at least it looks like it). So big thanks! This is some weird and really hard to debug issue.
Comment #118
damontgomery commentedThis is an update to #115 which was based on #104.
I was making too many assumptions about language paths. Now, we get the configuration for language prefixes to use those to detect languages and trim the paths.
Comment #119
damontgomery commentedSorry, I put the wrong comment number in the patch.
Comment #120
bgilhome commentedA small fix for foreach() errors if there are no languages (e.g. language module isn't enabled).
Comment #121
bapi_22 commentedHi All,
The applied patch will work only when you will add the redirection from the admin panel, coz it's converting alias into system path.
But Take a note: When I am migrating 100's of redirection from other sources, the alias is not converting into it's system path.
Comment #122
safetypinThe only case where alias based redirects don't work for us is when the source node is unpublished, and this is confusing behavior. Visitors get a 403 error and admin users are shown the source page and neither are redirected. There are several workarounds for our particular problem, but I disagree that this is the right way to handle situations where a visitor isn't authorized to access a page. Access should be blocked if the destination page is 403 to the visitor, but not the source. It doesn't matter whether or not the source page is accessible.
Comment #123
kkalaskar commentedFor quick fix I have created patch and added following code on line number 150 in redirect\src\EventSubscriber\RedirectRequestSubscriber.php
Comment #124
gmercer commentedI've rolled a patch with code change mentioned in #123 comment for 8.x-1.4
Comment #125
kamkejj commentedPatch https://www.drupal.org/files/issues/2021-03-31/redirect-path-alias-28796... (#124) works for me with Redirect 8.x-1.6
Our use case for needing this is that we got a spreadsheet of 700 URLs of redirects from our SEO team which only has the alias for the From URL. Using the redirect import module it's easy to create a CSV and import the URLs without having to write a script or manually removing aliases for unpublished content. This also let's us keep the unpublished content.
Comment #126
Rini Devraj commentedPatch redirect-path-alias-2879648-123.patch works for me with Redirect 8.x-1.6.
I've rerolled the patch for version 8.x-1.6.
Comment #128
mstrelan commentedA few issues with #120. As @bapi_22 mentioned in #121 this will only work for redirects added using the UI. Also as @malte.koelle experienced in #111 it doesn't work if the source path is prefixed with a slash.
It might be worth exploring if a link widget could be used for the source path as per #108. This would mean a redirect for an existing entity would be stored as entity:node/123, and a redirect for an arbitrary path would be stored as internal:/foobar.
I've also tested the patches in #102 and #124. Both of these are working for the most basic use cases I tested, but have their shortfalls as described in #103. I'm not sure the performance overhead is significant, but I did experience the collision when there are separate redirects for the system path and alias path. That is not a new issue though and can be reproduced without any patches. I would prefer to see redirects from the alias path take precedence over the system path though.
My suggestion is to carry on with the approach in #102 and earlier and ensure it's as robust and performant as possible.
Comment #129
mstrelan commentedThis patch is the same as #102 with some extra tests for language-specific redirects and creating an alias for a path that's already redirected.
Comment #130
luke.leberPlease feel free to debate, but I'm thinking that this may need to come with a major version update to the module, be shipped with an integration sub-module, or be a configurable option that is off by default. This particular issue has come up multiple times in our interactions with our content manager so I'm fairly sure it's a wide-spread misconception. That being said, it is likely only to be discovered after a redirect has been created whose
Fromvalue is an alias.Upon finding that it doesn't work, how many folks would follow through and delete the redirect? I don't think we can be reasonably sure that such redirects are cleaned up. As a result, if suddenly these redirects start working, it could have strange and hard to debug side-effects (from the perspective from a site owner or content editor).
Imagine the following scenario...
/node/1) with the alias/some-node./node/2) with the alias/some-newer-node./some-nodeto/some-newer-node./node/1to/some-newer-nodethat does work./node/1(it's been redirecting for years now and the page is going to be retired permanently)./node/10000) with the alias/some-node./some-nodecontent is now broken by a 301 redirect.Comment #131
anthonytm commentedI may be way off base here, but why have an existing node that cannot be accessed? This issue is caused because an alias exists for a node in Drupal for the path one is attempting to redirect. If the alias wasn't there, then the redirect would work. Am I missing something? Seems like deleting the node, or unpublishing and changing the alias would solve the problem. That way the redirect is using a non-existing path as the source which would result in a redirect to the destination.
Comment #132
zatox commented#131 makes a strong point. Why have accessible content that can't be accessed.
The initial problem seems graciously solved by simply removing/unpublishing the content that's behind the faulty redirect.
Are there actual use case here that we are not seeing? There must be with so much comments and so many followers of this issue. Can someone please come up with another use case than the one presented in the original post? I can't think of a good one.
I just don't see why the module should be changed. This issue should be solved by just removing what's there and that shouldn't be there.
All I can think of is trying to hide something (like /user/[user_id] pages for example, or https://www.drupal.org/project/drupal/issues/2828724 ). But it seems like bad practice to want to try to obfusctate something by "protecting" it with a redirect. Content should be first rendered inaccessible through traditionnal Drupal means like unpublishing or access control otherwise it would probably be easy to find a workaround to access whatever content you are trying to "protect". I guess there must be uses cases where this just can't be done and hence people default to a redirect.
Comment #133
berdirSorry for the silence here. To be clear, I have no intentions of committing a patch that will automatically work on aliases. There's just too much that could go wrong with redirects that suddenly work and content no longer being accessible then.
I think this should go back to earlier approaches that do the lookup during redirect creation and for those who want to support their existing redirects, there could be a script or so for them to run, not an enforced update function, which would have the same result.
I agree that there are valid use cases for this, for example on unpublished content, you currently either have to delete or manually change the alias, which depending on your setup, might not be possible for your users.
Comment #134
bkosborneI think #131 and #132 are missing the point a bit. The current behavior is inconsistent. Why should it work when using the system path as a redirect source but not when using the alias? I think either both should or should not work. The split behavior is confusing.
But #131 and #132 do bring valid criticism to the purpose of adding a redirect for an existing path to begin with. I can offer one explanation that I've encountered many times. A content type where you want to show a teaser of the content, but have the detail page redirect to some other page or website. For example, a Person content type that you want to show up in your site's search and "people" view, but redirect their detail page to that person's personal website.
However, I the use case I present above is probably better solved with some explicit checkbox on the content type itself to control this redirect behavior, and not involving the Redirect module at all. That's the approach we've recently taken, thought it does involve some custom code.
Comment #135
berdirYes, examples like that is exactly what https://www.drupal.org/project/rabbit_hole is designed to do.
Comment #136
znak commentedHi,
I added a small patch to quick-fix the problem with From aliases when we can't redirect from these aliases and added check on the existing path when we create redirect from aliases
But now From path has priority on
node/{nid}and after that on path alias on redirectComment #138
john_b commentedPossibly related to #3295763: does not work on non-node Webforms
Comment #139
eaglesnestqa commentedWe are still having issues with the URL redirect not being triggered when the redirect is created using URL alias. Is there a resolution to this issue? System is Drupal 9.3.xx with PHP 8
Comment #140
kiseleva.t commentedI have listing page "/node/1" with alias "/listing".
I can have path like "/listing/test" (facets pretty path enabled), it comes like "/node/1/test" to RedirectRequestSubscriber.
So redirect from "/listing/test" doesn't work, even with patch #124.
I've added logic to check request URI for redirects before trying to get alias for current path.
Comment #142
rajab natshahA re-role the the #129 patch to work with Redirect
1.8Comment #143
rajab natshahComment #144
aurora.luzzardiPatch #142 is not usable, it modifying a behavior, now instead of create a url redirect with the previous alias, it's creating a redirect with the new alias.
Besides patch #140 failing on tests, it's working as expected.
Comment #145
acbramley commentedPatch #142 can trigger the following error if
$pathsends up as an empty array.This doesn't happen without this patch because $path is just an empty string, which generates hashes and everything works.
I can trigger this locally by hitting a URL like
127.0.0.1/%2fThis popped up in our logs from malicious users trying to do weird stuff on our site. The fix is easy (check for empty $paths in the event subscriber) but writing a test is proving to be more difficult than expected.
Comment #146
acbramley commentedYeah it doesn't seem possible to test this in a functional test because of
UnroutedUrlAssembler::buildLocalUrlwhich ends up doing arawurlencodeAlso tidied up the other new tests, replacing the deprecated functions.
Comment #147
berdir1+ year after comments #131-135, I partially changed my opinion, but only partially.
As said back then, some of the use cases people have seem to overlap with rabbit_hole, which is a better solution for having content that shouldn't be accessible on its own path.
But there are valid use cases for this. We get support requests quite frequently about this, when people archive old content for example and want to keep it but still redirect it to another page. There are basically two options to handle that right now, without this patch.
a) Remove the alias of the archived content, then create the redirect.
b) Set up the redirect on the system path of the archived content. Problem is that it's then tied to that, if you delete that in the future, the redirect is broken.
Neither option is perfect. For most cases that *I* see, a) is better, but its hard to understand and requires multiple steps.
First, some relevant feedback on this patch:
I don't think this behavior is desired and it's inconsistent. Above, we still have the line to delete redirects and that is important, when changing an alias through pathauto or manually, you do _not_ expect that an existing redirect will override it and it will mean your content is inaccessible. Redirects get set up automatically, and if there's real content again on a certain path, that has to show up again.
If anything, we should restrict this logic here to not remove redirects if updating an alias and the alias does not change and only then.
The use case that this is trying to solve also already "just works" technically if you set the request path to the system path and not the alias, which is very similar to how link fields on a path/alias vs. selecting an entity via autocomplete (aka an entity:TYPE/ID URI). But unlike the autocomplete behavior, it's hard to understand for users.
The test coverage here needs to be adjusted to cover that scenario then.
To summarize, there are 3 possible options on how to deal with a redirect on an existing alias, a and b above, plus what this patch is adding, to actually support that aka c. I still have serious concerns about the current patch and its effect on existing sites. Site might have a considerable amount of redirects on aliases that they do not know about and that are "invisible" right now. By adding this they would suddenly start to work and content might no longer be accessible. I'm not sure how to deal with that in a backwards-compatible way. A setting maybe?
I still think I would prefer to have a patch that improves the usability of those two existing options a and b, for example by giving users a choice to do either directly from the add redirect form. Additionally to the warning message we have right now, we would display a radios element where users can choose between automatically deleting that existing alias on save, and a description that re-creating said alias will delete the redirect again. Or they let the system change the from path to the system path, tying it to the entity behind it then, no matter which alias it currently has. That could be done in a separate issue, and this could then tie into that with a third option, if enabled, that allows them to save the redirect as-is for the alias. But in my opinion, with the first two existing options (and existing modules like rabbit_hole), we can already cover 90% of the use cases. But I'm interested in hearing what use case still needs explicit support of redirecting on aliases.
I know that this is awkward for people who rely on this patch and have data that builds on it. That is in the end a risk you always have when relying on patches that change data structures or affect how things work on stored data. But if we introduce this with an optional setting, you can just enable that, or migrate to option a or b, someone could write an update script/batch for that.
Comment #148
berdirI started working on my idea in #2821158: Guide users who enter path aliases to use internal paths instead, very early UI only proof of concept, feedback welcome.
Comment #149
acbramley commentedReroll of #146
Comment #150
marelpup commented#149 isnt working for me
TypeError: Drupal\redirect\EventSubscriber\RedirectRequestSubscriber::__construct(): Argument #9 ($redirect_path_processor) must be of type Drupal\redirect\PathProcessor\RedirectPathProcessorManagerInterface, Drupal\Core\PathProcessor\PathProcessorManager given, called in /app/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 in Drupal\redirect\EventSubscriber\RedirectRequestSubscriber->__construct() (line 95 of modules/contrib/redirect/src/EventSubscriber/RedirectRequestSubscriber.php).
D9.5.11, php 8.1
Comment #151
damienmckennaFWIW #149 resolved some problems I had with path aliases on D10.0 not being created when user entities were modified. While I appreciate Berdir wants a more solid solution for the module's long term stability, #149 seems like a reasonable temporary solution for sites running into this problem.
Comment #152
damienmckennaFYI I should note that patch #149 did hit a minor issue:
The redirect admin page uses core's tag-baed caching. This suggests that the tags are not being invalidated correctly somewhere.
Comment #153
alina.basarabeanu commentedWe came across this issue using Drupal 10.1.5 and Redirect 1.9.0.
I created a new redirect from /old-page to /new-page but when navigating to /old-page I still can view the page.
The only change on the page is the breadcrumb pointing to the new page.
I did clear the cache and even ran cron but the redirect is not triggered.
Applying the patch from #149 fixed the redirect but the URL redirect is not added to either node's edit form.
Comment #154
guilherme-lima-almeidaHi everyone,
With:
The patch #149 works for me and the URL redirect is added to node edit form.
Comment #155
altcom_neil commentedHi all,
Sorry if this is cross pollinating with another issue but we had exactly this issue after migrating to D9 and updating to the new version of the Redirects module. It caused a lot of confusion with clients trying to manage their content as in D7 the alias redirects worked but not in D9 after the upgrade.
One way we solved this was to integrate not only showing the redirects to a node but the redirect away as well. This makes it easier for a user when editing the node to see it is being redirected to another URL. And this simplifies the creation of a redirect from an old node to a new one.
There is a patch here that some people may find useful https://www.drupal.org/project/redirect/issues/3386107
Comment #156
uttam commentedWas going through this same problem, the module wasn't working with path aliases for the redirection. The patch #142 works for me.
Thanks @Rajab Natshah
Comment #157
paucala commentedThe patch #142 works for me also. Thanks
Comment #159
someshver commented#142 is working for me also. Thanks
Comment #160
robert-arias commented#142 and #149 could introduce a redirect loop if:
Re-attaching #146 patch without feature ofUse the patch in #161// source = [new alias], dest = [existing redirect].Comment #161
robert-arias commentedRe-attaching #146 patch without feature of
// source = [new alias], dest = [existing redirect].- correcting my own patch.Comment #162
acbramley commentedLet's get this work into the MR? Patches are dead now.
Comment #165
robert-arias commented✅ - opened MR with changes from #161.
Comment #166
prashant.cComment #169
rajab natshahUpdated the MR
After Redirect 8.x-1.10 was released
Attached a static
redirect--2024-08-11--2879648--mr-109.patchfileto be used with composer patches
Comment #170
damienmckennaThere are two test failures:
and:
Anyone want to try fixing these?
Comment #172
acbramley commentedThe 2 failures were from the same 2 lines, essentially testing some functionality which I can not see implemented anywhere.
The assertions were testing that the existing alias based redirect was updated when the node had its alias changed. I personally can't see any code that would add that functionality, and IMO is not necessary.
The whole idea of redirecting from a node alias would mostly be around redirecting away from stale content easily (by using the alias). If we want to add automatic updates to existing alias redirects then we could do that in a follow up, especially seeing how long this issue has taken to get resolved.
Therefore, I've removed the assertions.
Comment #173
sayaliumap commentedHi, I have applied patch #169 o Drupal 10.3.2 and Redirect 8.x-1.10, the redirection is working properly. However, I am getting an error after logout Drupal. Is anyone aware of this how this needs to be resolved?
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') ORDER BY LENGTH(redirect_source__query) DESC' at line 1: SELECT rid FROM "redirect" WHERE hash IN () ORDER BY LENGTH(redirect_source__query) DESC; Array ( ) in Drupal\redirect\RedirectRepository->findRedirectByHashes() (line 142 of /code/web/modules/contrib/redirect/src/RedirectRepository.php).
Comment #174
acidaniel commentedI've tested the patch #169 with Drupal 10.3.3 and Redirect 8.x-1.10, I see all redirections are working properly, even the existing ones that had no issues before applying the patch. Also I took a look to the dblog after applying the patch and tested several redirects. No issues found or error messages logged.
Comment #175
summit commentedHi, is patch #169 good to go? Greetings,
Comment #176
summit commentedHi, Patch #169 working good. greetings,
Comment #177
sayaliumap commentedI've added the patch #169 with Drupal 10.3.10 and Redirect 8.x-1.10 ,
Getting below error. Anyone have any solution for this?
Issue : Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ') ORDER BY LENGTH(redirect_source__query) DESC' at line 1: SELECT rid FROM "redirect" WHERE hash IN () ORDER BY LENGTH(redirect_source__query) DESC; Array ( ) in Drupal\redirect\RedirectRepository->findRedirectByHashes() (line 142 of /code/web/modules/contrib/redirect/src/RedirectRepository.php).
Comment #178
alexl commentedI've added the patch #169 and i have this error :
TypeError: array_diff_assoc(): Argument #2 must be of type array, null given in array_diff_assoc() (line 154 of modules/contrib/redirect/src/RedirectRepository.php).
$query does not exist in findRedirectByHashes function.
EDIT :
in fact this bug only occurs if you also apply a patch from https://www.drupal.org/project/redirect/issues/2831605
Comment #179
kiwad commentedrefreshing status considering the last 2 comments...
Comment #180
mark_fullmer1. Noting that the error in #178 only occurs in conjunction with the in-progress enhancement #2879648: Redirects from aliased paths aren't triggered, it seems that accommodating that should be done as part of that enhancement, rather than this scope.
2. I'm unable to reproduce the problem described in #177. More information (steps to reproduce) would be needed.
3. The latest comment on the MR is addressed.
Based on the above, my own functional testing, and the passing automated tests, I'm setting this back to RTBC.
Comment #181
berdirI have not yet reviewed the changes since I provided feedback in #147/#148 but my opinion on this has not changed. I understand that many people are interested in this and use this patch, but for everyone who does use the patch, there are literally thousands of sites out there who don't. Those sites might have inactive redirects for some reason that they do _not_ expect to work and with this, their content might suddenly become inaccessible.
At this point, I have no plans to merge this change.
I proposed an alternative solution in #148 that guides users through creating a valid redirect when creating them. I haven't managed to find time to get back to that, but I'd be much more open to merging that instead. Sites who rely on this patch will then need an update path to convert aliases to the system path.
Comment #182
mark_fullmerThanks for the clarification on the thinking, @berdir. In that case, I think it might be sensible to more clearly label this issue as something that will not be merged, and leave it going for people who want to patch the module, and direct folks to #2821158: Guide users who enter path aliases to use internal paths instead to complete that work. Also, based on the progress on that issue, it could probably be renamed to something like "Check for path aliases and guide users to use internal path"?
Comment #183
mark_fullmerComment #184
mark_fullmerComment #185
mark_fullmerI've updated the title & description in #2821158: Guide users who enter path aliases to use internal paths instead to indicate that the maintainers do not plan to support URL aliases. Work can continue there. This issue can probably be closed as "won't fix."
Comment #186
adinancenci commentedI am still capable of creating loops with patch #169
Comment #187
nigelcunningham commentedHi @Berdir and @mark_fullmer.
I haven't read the whole issue so please forgive me if I'm restating arguments that have already been made. I did search for phrases related to my post but it would take too long to read the whole thing.
I would like to suggest that supporting aliases is important from a content editor experience point of view - we should be seeking to make Drupal as easy to use as possible. I can see there are probably issues around aliases being changed separately to redirect being created/edited, but I'd humbly suggest that providing the best CX should at least drive a reconsideration of your position here.
FWIW, I found this issue after dealing with a client reported bug that a redirect wasn't working as expected. They had a published node with the name they were attempting to redirect from. To get the redirect working, I needed to change the node name (and I unpublished it).
Comment #188
mark_fullmerI believe the main resistance to supporting aliases is stated in comment #181 -- the possibility for existing redirects in existing sites to behave differently after this change.
Trying to look for a win-win solution here, what about the support of aliases being an opt-in configuration option? That would avoid the concern stated in #181, right?
Comment #189
nigelcunningham commentedI like the point in #181 that the patch shouldn't cause a change in behaviour with pre-existing comment.
Re the support of aliases being an opt-in configuration option, that sounds like a good idea. Would it would be problematic to accept aliases in the add/edit form and optionally translate them to the unaliased version on submission, perhaps with an explanation there?
Comment #190
kevinquillen commentedCatching up on this issue - I just ran into a need to support a case in a Drupal site where the path isn't changing, but its query strings are (which triggers different application parts on the page from React, etc) and is used for marketing purposes. The Drupal node just houses the components for this part.
i.e.
foo-page?param_1=123¶m_2=456needs to redirect to:
foo-page?param_1=789¶m_2=456theres no other way I can think of, in the UI, to support such a case.
In my case, I adapted parts of this patch to do the following:
This appeared to work in my case - I only want this behavior when there is a query string detected and an existing alias is found. Are there any drawbacks to this?
Comment #191
nigelcunningham commentedIs there any chance that you might go from not having query parameters on a URL to having them? If that's a possibility, I would add the cache context on all paths where that could happen.
Apart from that, I'm not seeing any potential issues from reading your description of what you're doing.
Comment #192
kevinquillen commentedNot really, its in support of a legacy API outside of Drupal, embedded in a node in React (lots of identifiers and marketing related values in the query string). So its one Drupal node, but thousands of possible query string combinations.
Comment #193
nigelcunningham commentedThumbs up, then, based on my superficial understanding :)
Comment #194
mark_fullmerComment #195
john_b commentedI would vote in favour of having redirects of aliased paths working out of the box. If I had a vote!
For the non-technical user building Drupal sites without a developer, the the fact redirects of aliases don't work, and even the concept of an alias, can be confusing.
Comment #196
kevinquillen commentedThis also affects the Domain Redirect functionality as well. You have to patch in support for query string handling there, and particularly if you use Domain Unique Path Alias.
Comment #197
mark_fullmerHere's a scenario that illustrates "there are probably issues around aliases being changed separately to being created/edited":
1. Content editor creates a node (
/node/123) with alias (/policies).2. Content editor (same or different person) decides that the about page should be retired or replaced, and creates a redirect from
/policiestohttps://external-site.com/policies.3. Content editor wants to do something/anything with the original /policies page. When the content editor goes to
/policiesto **edit** that page, they are now redirected and probably quite confused. Even if the content editor knows what's going on, they would now have to find the node in the content listing/admin/contentand click "Edit" to be able to edit the content.I no longer think this change would unambiguously improve the content editorial experience. It comes with its own risks for confusion.
That said, the latest change to the MR adds an opt-in setting to allow redirects when the source path is an alias of an existing internal path. Setting to needs review.
Suggested testing
1. Create a node with a URL alias (/one).
2. Create a redirect from the aliast (e.g., /one -> /two)
3. Visit /one and verify that the behavior of the Redirect module remains as is has been -- /one is NOT redirected to /two
4. Go to /admin/config/search/redirect/settings and turn on "Allow redirects from aliases."
5. Visit /one and verify that is now redirects to /two
Comment #198
bkosborneThis happens to our editors frequently. We don't use a patch from this issue, but our editors and team know that you can do the workaround of creating a redirect from an existing path by using the system path as the source. E.g., instead of creating the redirect from /policies -> new page, you create it from /node/123 -> new page. The end result is the same level of confusion. The only way to edit the original page is to find it in the content dashboard.
Comment #199
albert volkman commentedPerhaps, for administrators, instead of redirecting the page display a banner stating that a redirect is in place and link to the redirect entity.
Comment #200
bernardopaulino commentedAs a follow-up to #179, I’ve created a new patch that reintroduces the $query parameter in the
findRedirectByHashesmethod to maintain compatibility with other existing patches. This aligns with the implementation in the current stable release of the module.I’ve also updated the return values of the
findMatchingRedirectMultiple()andfindMatchingRedirect()methods to reflect this change.This patch is based on the latest commit from merge request !109.
Comment #201
bernardopaulino commentedI forgot to include the RedirectPathProcessorManager in the previous patch. Use this one instead.
Comment #202
john_b commented@bernardopaulino thanks for the patch. It is giving me an error on Drupal 11.2.2, PHP 8.4.
TypeError: Drupal\redirect\EventSubscriber\RedirectRequestSubscriber::__construct(): Argument #9 ($redirect_path_processor) must be of type Drupal\redirect\PathProcessor\RedirectPathProcessorManagerInterface, Drupal\Core\PathProcessor\PathProcessorManager given, called in ~/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 in Drupal\redirect\EventSubscriber\RedirectRequestSubscriber->__construct() (line 97 of modules/contrib/redirect/src/EventSubscriber/RedirectRequestSubscriber.php).
Comment #203
john_b commented@bernardopaulino thanks for the revised patch 2879648-path-alias-redirect-201.patch. It is giving me an error on Drupal 11.2.2, PHP 8.4.
TypeError: Drupal\redirect\EventSubscriber\RedirectRequestSubscriber::__construct(): Argument #9 ($redirect_path_processor) must be of type Drupal\redirect\PathProcessor\RedirectPathProcessorManagerInterface, Drupal\Core\PathProcessor\PathProcessorManager given, called in ~/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 in Drupal\redirect\EventSubscriber\RedirectRequestSubscriber->__construct() (line 97 of modules/contrib/redirect/src/EventSubscriber/RedirectRequestSubscriber.php).
Comment #204
john_b commented@mark_fullmer
I performed the tests suggested in #197 and it was fine. I also tested in conjunction with redirect_bulk and csv upload of bulk redirects, and it works. Tested on Drupal 11.2.2 + PHP 8.4.
I have not set to RTBC owing to the reported failing of unit tests on the MR.
Given the strong demand for this feature, and the decision of the maintainers in #181 not to support it, I suggest creating a new project with a tagged release for the benefit of users who want the feature.
Comment #205
damienmckennaThe MR has some major conflicts with 8.x-1.x, and some test failures.
Comment #206
cboyden commentedThere's a problem in the updated MR. In the function findRedirectByHashes, there is no source for the variable $cacheable_metadata, so it's always going to be undefined.
Comment #207
acbramley commentedRestoring IS
Comment #208
acbramley commentedSimilar to #3057250: Validation issue on adding url redirect the merge conflict resolution here completely broke this MR. I've reverted back to the previous commit and re-merged. The RedirectRepository conflicts were quite hard to resolve but the alias test at least seems to be passing.
Comment #209
acbramley commentedThis is green now and we have the config option to opt-in to this. Would this make it more appealing to commit?
Comment #210
someshver commentedI’ve re-rolled the patch for version 8.x-1.12 since the previous patch was incompatible with this version.
Comment #211
someshver commentedComment #212
someshver commentedHere’s the correctly named patch for version 8.x-1.12.
Comment #213
acbramley commentedWe found issues with this hunk of code after deploying to production:
This was breaking preview_link functionality through some weird interactions with getUrlIfValid.
This was added in https://git.drupalcode.org/project/redirect/-/merge_requests/109/diffs?c...
@mark_fullmer do you recall exactly what this was achieving? From my testing, we don't need this check at all. With some better handling in the path processor we can simply not check for the alias when the config isn't set (see latest commit).
I also fixed an assertion in one of the new tests.
Comment #216
sakthi_dev commentedCreated a MR with current changes.
Comment #218
acbramley commented@sakthi_dev there was already an MR up, please contribute to that instead.
Comment #219
acbramley commentedThe MR is heavily conflicting now due to https://git.drupalcode.org/project/redirect/-/commit/7c7311ba4fca90483ae...
Comment #221
twodJust fixed the merge issues and manually tested that redirecting from an alias still worked (once I remembered to enable it...), so still needs some work.
Comment #222
falco010The current diff of MR 109 does not apply to 1.12 version of this module anymore due to this:
The patch #212 causes infinite redirect errors on some pages.
Hereby, a new patch is provided that should work and cleanly apply to the 1.12 version. The patch is based on the current 109 MR.
Comment #223
waropd commentedPatch from #222 wouldn't apply on 1.13
Manually got everything from the MR for a working patch
Comment #224
waropd commentedCorrect patch with the new files
Comment #225
jculver commentedLast patch causes errors: Drupal 11.3.8, Redirect 1.13 .
Reverting to 1.12 and the 212 patch still works
Comment #226
mrdalesmith commentedAnyone dropping into this issue and not being minded to read all the comments, note that in this comment https://www.drupal.org/project/redirect/issues/2879648#comment-14298777 the maintainer has said they won't be merging this patch. By applying it you'll be committing yourself to issues where the changes here continue to conflict with any updates applied to the project.
You should make a serious judgement call on whether you really need this functionality - rather than using rabbithole or the redirect module's supported suggestion of adding a URL alias to the node you want to redirect to. This issue only affects trying to redirect the URL alias of an existing node to another node's path: arbitrary redirects for any path you want can be added and will work fine.
Comment #228
heshamkh commentedRerolled patch #224 for Redirect 1.13.
Patch #224 applies cleanly but causes a fatal error:
Error: Call to undefined method Drupal\redirect\RedirectRepository::getHashesByPath()
in Drupal\redirect\RedirectRepository->findMatchingRedirectMultiple()
This reroll keeps the changes from #224 and restores the missing helper methods from earlier patch iterations:
- RedirectRepository::getHashesByPath()
- RedirectRepository::findRedirectByHashes()
Tested with:
- Drupal 10.6.8
- Redirect 1.13.0
- PHP 8.x
The patch applies cleanly via Composer and fixes the fatal error.
Comment #230
neclimdulHow could a non @internal public method on a service be removed like this in a patch release?
Comment #231
daaan commentedThis reroll is based on redirect-2879648-224-reroll.patch (#224), updated to work with Drupal 11.4+.
Problem
The #224 reroll extends PathProcessorManager and collects inbound processors via the service_collector tag and addInbound(). These APIs were removed in Drupal core 11.4.0 (#3571046), causing a fatal error:
Error: Call to undefined method Drupal\Core\PathProcessor\PathProcessorManager::addInbound()
in Drupal\redirect\PathProcessor\RedirectPathProcessorManager->addInbound()
Solution
Changes compared to #224
Test plan
Comment #232
brandonlira commentedTested patch #231 successfully.
Environment:
- Drupal 11.4.4
- Redirect 1.13.0
- PHP 8.3
The patch applied cleanly and fixed redirects from active aliased source paths. Before applying it, those requests returned `200` and rendered the aliased entity. After applying the patch and clearing cache, they correctly return `301` with the expected `Location` header.
Thanks for the Drupal 11.4-compatible reroll.
Comment #233
eduardo morales albertiAdding a similar issue #3419355: System path redirects create redirect loop
Comment #234
damienmckennaFor anyone who needs it, this is a version of MR 202 (11.4+ only) that applies cleanly when also using #3245137: Add a 'URL Redirects' tab to ALL applicable content entity edit forms (only nodes supported yet); it doesn't have all of the test or .gitlab-ci.yml changes, but those aren't needed locally.
Comment #235
damienmckennaThis is MR 109 designed to work with #3245137.