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.
If you have a module implementing hook_url_inbound_alter(), global redirect notices the path isn't the same as $_REQUEST['q'] and redirects you to the system path, which means your pretty URLs cease to work. I verified this with a custom module, but not with locale or others which implement the hook yet.
Attached patch runs the hook again, then checks if it's altered by the hook or not, which is obviously less than ideal. Not sure what the other options yet which could be both generic and efficient.
Comment | File | Size | Author |
---|---|---|---|
#7 | urlinbound-774950-2.patch | 669 bytes | wmostrey |
#1 | globalredirect_7.x-1.x-dev_774950-1.patch | 1.35 KB | jm.federico |
inbound.patch | 1.78 KB | catch | |
Comments
Comment #1
jm.federico CreditAttribution: jm.federico commentedYour patch includes a file not form global redirect, re-rolling!
Comment #2
nicholasThompson@Catch - could you provide an example custom module which uses hook inbound alter?
I have tried the above patch and although it stops the redirect loop, it also exposes duplicate urls. Basically, it's fixing one problem by completely disabling the system. Of course, it's very possible that my custom module is at fault here ;)
I made a module called gr_dummy which was simply this:
(this is mostly "inspired by" purl).
In GlobalRedirect.module, I added this after
globalredirect_request_path
and before locale_language_url_rewrite_url.Any thoughts?
Comment #4
catchYeah the patch just disables redirects for those paths, I don't think there's any way at all for global redirect to work for hook_url_inbound_alter() in the same way it does for path aliases - you can put anything you like in hook_url_inbound_alter() and there's zero way to do a reverse lookup. I'm not a fan of hook_url_inbound_alter(), this was the first and hopefully last time I'll ever have had to use it.
#832862: hook_url_inbound_alter breaks the module would help here at least a bit.
Comment #5
nicholasThompsonCould you provide your dummy module which you used to test it please?
Comment #6
wmostrey CreditAttribution: wmostrey commented(Is this a duplicate of #832862: hook_url_inbound_alter breaks the module?)
An easy example is the D7 port of the purl module:
Enable the globalredirect and the purl module, and all admin/* urls result in an endless loop.
Comment #7
wmostrey CreditAttribution: wmostrey commentedI can confirm that the proposed solution in #2 works for me, and it solves the problem with the purl module mentioned in #6. Patch attached.
Comment #8
thebuckst0p CreditAttribution: thebuckst0p commentedIs this a dup of #1101178: Check for outbound url rewrites, or are the inbound and outbound issues separate?
Comment #9
wmostrey CreditAttribution: wmostrey commentedIt's not a duplicate, a problem still exists.
Comment #10
jm.federico CreditAttribution: jm.federico commentedMarking #986048: Redirect loop as a dup
Scaling to major, this breaks the module.
Comment #11
rwohlebCorrect me if I'm wrong, but in the patch from #7 shouldn't
be
Comment #12
rwohlebAnother potential issue with patch #7 is that it uses drupal_alter(). The function drupal_get_normal_path() avoids this function so that it can guarantee execution in reverse order of hook_url_outbound_alter(). While unlikely to be an issue for most people, it would probably be better to keep the same execution order.
Comment #13
wmostrey CreditAttribution: wmostrey commentedComment #14
tohms CreditAttribution: tohms commentedAny updates on that issue? Anything we could do?
Comment #15
mrfelton CreditAttribution: mrfelton commentedPatch in #7 does stop globalredirect falling into a redirect loop when spaces/purl is enabled, but as noted in #4 it just disables globalredirect and therefore renders it pretty useless.
Comment #16
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedThere is also http://drupal.org/project/redirect
Comment #17
jm.federico CreditAttribution: jm.federico commentedI just opened a new issue #1445934: Fix logic of module, broken when other modules implement prefixes. which as "@Dave Reid" mentions it might be a dup of this. Even if not they are related.
Patch there fixes the issue mentioned here.
Cheers
Comment #18
MGParisi CreditAttribution: MGParisi commentedIt looks as if Global Redirect fixed their issue, has this patch been applied to this module?
Comment #19
webservant316 CreditAttribution: webservant316 commentedIs this problem fixed? The http://drupal.org/project/subdomain module is incompatible with global redirect until this problem is fixed.
Comment #20
wizonesolutionsIn my opinion, this is not inherently broken. Implementing modules should also implement
hook_url_outbound_alter()
so that the URL gets generated the same way withurl()
— Global Redirect respects this. If you only change it one way, then you will get this problem.For example, on one client site, I ran into this because we implement a custom language fallback logic and change the internal path served by Drupal if we don't have a translation available for the language and alias requested. This of course confuses Global Redirect; it sees that the alias I'm trying to go to doesn't exist for the language I'm on. I work around this by implementing
hook_url_outbound_alter()
and hijacking$options['language']
. I change it to our fallback language (which does have an alias) so that when Global Redirect does its alias check, it finds that we are where we should be and leaves us alone.Another way to do this is to implement
hook_module_implements_alter()
and swap outglobalredirect_init()
for your own custom implementation that does some setup (e.g. changes$_GET['q']
and then callsglobalredirect_init()
and then fixes$_GET['q']
back). I don't recommend this.Other than this, the fix should be in the Subdomain module itself. That module knows how best to do it. We cannot possibly cover all cases in Global Redirect without changing the very behavior for which people install the module.
Comment #21
gnassar CreditAttribution: gnassar commentedIf this was indeed related to #1445934: Fix logic of module, broken when other modules implement prefixes. (and it seems like it would be), this would now actually be a duplicate of #1843500: Wrong usage of prefix in Global Redirect (Patch attached). Seems like a better solution to what we have here.