Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When I create a new redirect from /node/1
to /node/2
it works fine but when I use path alias e.g. /foo
to /node/2
it does not redirect. This happens because the hash that gets generated while saving a new redirect is based on the user input i.e it can be alias or node path but when we try to match a path we use system path and hence does not match.
Steps to reproduce
- Create a redirect from
node/1
to/node/2
and confirm it works - Create a redirect from
foo
to/node/2
and confirm it works - Create a node with alias
/bar
- Add a redirect from
bar
to/node/2
and confirm it does not work
Proposed resolution
The following approaches have been discussed:
- Get consistency in the hash generation function by always using system path
- Find redirects that match either the alias or system path
- Convert aliases to system paths before they're saved
Remaining tasks
- Decide on the preferred approach
User interface changes
TBD
API changes
TBD
Data model changes
TBD
Comment | File | Size | Author |
---|---|---|---|
#149 | 2879648-149.patch | 21.39 KB | acbramley |
#146 | interdiff-2879648-142-146.txt | 4.38 KB | acbramley |
#146 | 2879648-146.patch | 21.58 KB | acbramley |
| |||
#143 | interdiff-129-142.txt | 9.87 KB | Rajab Natshah |
#142 | 2879648-142.patch | 21.25 KB | Rajab Natshah |
|
Comments
Comment #2
ameymudras CreditAttribution: ameymudras as a volunteer commentedComment #3
ameymudras CreditAttribution: ameymudras as a volunteer 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 CreditAttribution: ameymudras as a volunteer commentedThanks, could you please provide the existing issue link?
Comment #6
Berdir#2821158: Document that URL redirects work from node/{nid} but not alias is the related issue.
Comment #7
Wim LeersComment #8
Wim LeersFor #4.
Comment #9
enzipher CreditAttribution: enzipher commentedI ran into this issue as well, and here is an alternative patch where the path check is done in the
generateHash
function. I'm not sure if this has a performance impact or not, but it seems better to handle it there.Comment #11
jmuzz CreditAttribution: 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 0
Can 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 CreditAttribution: 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 CreditAttribution: Ravi Shankar Karnati commentedHi @ameymudras - #2 patch is not able to apply with the redirect module version 1.3
Comment #18
Ravi Shankar Karnati CreditAttribution: 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) CreditAttribution: Anonymous at CTI Digital 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 CreditAttribution: maximpodorov commentedPatch #18 is reworked, reformatted and rerolled.
Comment #23
maximpodorov CreditAttribution: maximpodorov commentedLanguage parameter is added to path alias processing.
Comment #24
g.weston CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: sonu.raj.chauhan as a volunteer and for Publicis Sapient 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 CreditAttribution: sonu.raj.chauhan as a volunteer and for Publicis Sapient commentedComment #29
sonu.raj.chauhan CreditAttribution: sonu.raj.chauhan as a volunteer and for Publicis Sapient commentedComment #30
sonu.raj.chauhan CreditAttribution: sonu.raj.chauhan as a volunteer and for Publicis Sapient commentedComment #31
SaraKlasson CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: Feng-Shui commentedComment #39
Feng-Shui CreditAttribution: Feng-Shui commentedPrevious patch had an issue with the update hook.
Comment #40
Feng-Shui CreditAttribution: 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 tests
tag for now.Going to leave this here now until it gets a review.
Comment #41
Fastmover CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: Feng-Shui commentedComment #47
Feng-Shui CreditAttribution: 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 CreditAttribution: Feng-Shui commentedChanges as requested.
Comment #50
Wakuiy CreditAttribution: 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_language
is 'und', however getPathByAlias returns the input value when using either$redirect_language
orLanguage::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 CreditAttribution: 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_SPECIFIED
and 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 theelseif
should 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 CreditAttribution: 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 CreditAttribution: Feng-Shui commentedAhhh, my bad you're saying that the
elseif
should 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 CreditAttribution: Feng-Shui commentedLooks like an additional cache clear is needed in the failing test.
Comment #57
rahulrasgon CreditAttribution: rahulrasgon at QED42 commentedPlease review the patch.
Comment #59
Feng-Shui CreditAttribution: 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 CreditAttribution: Kuldeep K commented#56 patch worked for me. post_update is running correctly in that. Thanks for the help.
Comment #61
herved CreditAttribution: 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 CreditAttribution: micnap at Four Kitchens 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 CreditAttribution: 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/42
We would need to change slightly the the detection in
\Drupal\redirect\EventSubscriber\RedirectRequestSubscriber::onKernelRequestCheckRedirect
to add "entity:" if we're on a node or entity path.This wouldn't require any risky or long updates.
Comment #64
micnap CreditAttribution: micnap at Four Kitchens commentedWas able to troubleshoot the infinite loop in patch #57. Looks like it was just a ++ left off of a counter.
Comment #65
micnap CreditAttribution: micnap at Four Kitchens commentedComment #66
callinmullaney CreditAttribution: callinmullaney at Four Kitchens commentedPatch #64 seems to have resolved the issue for me. We were able to create new redirects with path aliases.
Comment #67
herved CreditAttribution: 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 CreditAttribution: lolandese at Cognizant Technology Solutions 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
$path
will 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 CreditAttribution: lolandese at Cognizant Technology Solutions 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 CreditAttribution: smustgrave commentedQuestion what is the purpose of
Why wouldn't we use the language of the redirect itself?
Comment #72
paper boyThanks 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 CreditAttribution: lolandese at Cognizant Technology Solutions 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 CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: enriquelacoma at NTT DATA for European Commission and European Union Institutions, Agencies and Bodies commentedI tested the last patch and got some weird results, i did this:
Comment #77
enriquelacoma CreditAttribution: enriquelacoma at NTT DATA for European Commission and European Union Institutions, Agencies and Bodies commentedI updated the test to fix some problems with path alias activation.
Comment #78
enriquelacoma CreditAttribution: enriquelacoma at NTT DATA for European Commission and European Union Institutions, Agencies and Bodies commentedThe previous patch didn't apply, retest with a new version.
Comment #79
enriquelacoma CreditAttribution: enriquelacoma at NTT DATA for European Commission and European Union Institutions, Agencies and Bodies commentedI updated last patch to fix some testing errors related to the use of language on the operations.
Comment #80
enriquelacoma CreditAttribution: enriquelacoma at NTT DATA for European Commission and European Union Institutions, Agencies and Bodies commentedI updated some test to use the current language, in line alias language
Comment #81
jweedman CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: herved commentedThe fact that the hash gets generated always from the source path (e.g: node/2) in
\Drupal\redirect\Entity\Redirect::preSave
while theredirect_source__path
in 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::onKernelRequestCheckRedirect
to 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 CreditAttribution: herved commentedSeems like tests are passing.
Feedback on this approach are most welcome and appreciated.
Comment #85
mgam737 CreditAttribution: 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 CreditAttribution: enriquelacoma at NTT DATA for European Commission and European Union Institutions, Agencies and Bodies 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 CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: enriquelacoma at NTT DATA for European Commission and European Union Institutions, Agencies and Bodies 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 CreditAttribution: enriquelacoma at NTT DATA for European Commission and European Union Institutions, Agencies and Bodies commentedComment #91
enriquelacoma CreditAttribution: enriquelacoma at NTT DATA for European Commission and European Union Institutions, Agencies and Bodies commentedI updated patch #83 to keep redirections when changing the alias of the of an entity.
Comment #92
enriquelacoma CreditAttribution: enriquelacoma at NTT DATA for European Commission and European Union Institutions, Agencies and Bodies commentedI updated patch #83 to keep redirections when changing the alias of the of an entity.
Comment #93
enriquelacoma CreditAttribution: enriquelacoma at NTT DATA for European Commission and European Union Institutions, Agencies and Bodies commentedUse the method createDuplicate to create the new redirection when changing an alias.
Comment #94
herved CreditAttribution: 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 CreditAttribution: vidorado as a volunteer and at Biko2 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 CreditAttribution: herved commented@vidorado
Looking at your patch #95, I don't understand how you can have an alias at this point in:
The
$source_path
we get as argument is passed through the inbound processor in\Drupal\redirect\EventSubscriber\RedirectRequestSubscriber::onKernelRequestCheckRedirect
so 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 CreditAttribution: vidorado as a volunteer and at Biko2 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$path
is 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 CreditAttribution: vidorado as a volunteer and at Biko2 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
RedirectRequestSubscriber
in 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 CreditAttribution: enriquelacoma at NTT DATA for European Commission and European Union Institutions, Agencies and Bodies 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 CreditAttribution: vidorado as a volunteer and at Biko2 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 CreditAttribution: enriquelacoma at NTT DATA for European Commission and European Union Institutions, Agencies and Bodies commentedThere was an error in the test of patch #99, i updated the test in this patch
Comment #102
herved CreditAttribution: 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 CreditAttribution: 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::preSave
Cons:
- it alters the hash generation, hashes are not always in sync anymore with the
redirect_source__path
in 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::onKernelRequestCheckRedirect
to 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 CreditAttribution: herved commentedHere is the 3rd approach, without tests.
Comment #105
Neslee Canil PintoComment #106
smustgrave CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: 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
paper boyI 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 CreditAttribution: malte.koelle at Unic 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 CreditAttribution: 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
getPathByAlias
is 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 CreditAttribution: damontgomery at Palantir.net for Tableau 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 CreditAttribution: damontgomery at Palantir.net for Tableau 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 CreditAttribution: damontgomery at Palantir.net for Tableau 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 CreditAttribution: damontgomery at Palantir.net for Tableau 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 CreditAttribution: damontgomery at Palantir.net for Tableau commentedSorry, I put the wrong comment number in the patch.
Comment #120
bgilhome CreditAttribution: bgilhome commentedA small fix for foreach() errors if there are no languages (e.g. language module isn't enabled).
Comment #121
bapi_22 CreditAttribution: bapi_22 at Globant 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 CreditAttribution: 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 CreditAttribution: gmercer commentedI've rolled a patch with code change mentioned in #123 comment for 8.x-1.4
Comment #125
kamkejj CreditAttribution: kamkejj at Nerdery for Nestle Purina PetCare - United States 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 CreditAttribution: Rini Devraj as a volunteer and at TATA Consultancy Services 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 CreditAttribution: mstrelan at PreviousNext for Service NSW 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 CreditAttribution: mstrelan at PreviousNext for Service NSW 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
From
value 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-node
to/some-newer-node
./node/1
to/some-newer-node
that 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-node
content is now broken by a 301 redirect.Comment #131
anthonytm CreditAttribution: 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 CreditAttribution: Zatox as a volunteer and 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 CreditAttribution: Znak at Drupal Ukraine Community for Drupal Ukraine Community 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 CreditAttribution: John_B commentedPossibly related to #3295763: does not work on non-node Webforms
Comment #139
eaglesnestQA CreditAttribution: 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 CreditAttribution: kiseleva.t as a volunteer and at FFW 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 Natshah CreditAttribution: Rajab Natshah at Vardot for Vardot commentedA re-role the the #129 patch to work with Redirect
1.8
Comment #143
Rajab Natshah CreditAttribution: Rajab Natshah at Vardot for Vardot commentedComment #144
aluzzardiPatch #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 CreditAttribution: acbramley at PreviousNext for Service NSW commentedPatch #142 can trigger the following error if
$paths
ends 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/%2f
This 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 CreditAttribution: acbramley at PreviousNext for Service NSW commentedYeah it doesn't seem possible to test this in a functional test because of
UnroutedUrlAssembler::buildLocalUrl
which ends up doing arawurlencode
Also 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: Document that URL redirects work from node/{nid} but not alias, very early UI only proof of concept, feedback welcome.
Comment #149
acbramley CreditAttribution: acbramley at PreviousNext for Service NSW commentedReroll of #146
Comment #150
MarelPup CreditAttribution: MarelPup as a volunteer 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 CreditAttribution: 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 CreditAttribution: 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