I noticed recently when I got my blog added to Planet Drupal that there were 2 URLs associated with each term, e.g.:
http://freestylesystems.co.uk/taxonomy/term/14
http://freestylesystems.co.uk/taxonomy/term/14/0
This is a side effect of the taxonomy system where /0 is 'the "depth" selector for hierarchical taxonomies - 0 means infinite depth' (quote from greggles in IRC).
At first I thought my patch wouldn't work since there are more examples of URLs with /0 on the end and they might be problematic. The logic in globalredirect.module seems to take care of this:
if ($alias = drupal_get_path_alias($request)) {
// If alias is different to the request, redirect...
if ($alias != $request) {
drupal_goto($alias, $query_string, NULL, 301);
}
// If the request produced by the trim above differs to the request then redirect (basically, de-slash)
if ($request != $_REQUEST['q']) {
drupal_goto($request, $query_string, NULL, 301);
}
}
First a check is made on $request for a path alias, whilst also being assigned to $alias. This means that any URL ending with /0 that does not have an alias set will not be redirected.
Do you think this Is watertight enough to commit?
| Comment | File | Size | Author |
|---|---|---|---|
| globalredirect.module.patch | 569 bytes | psynaptic |
Comments
Comment #1
nicholasthompsoni always wondered what that /0 did...
I dont think we can commit this patch because it could effect people who actually USE the '/0', for example if someone defined their own view which had an argument which was "/0"...
Comment #2
psynaptic commentedIs there anything in the system that would allow us to be sure we're trimming only the unwanted /0's?
Comment #3
nicholasthompsonNot that I can think of. I believe its a little unfair of a module to simply assume an argument can be removed off the URL.
This is a valid concern but I cannot think of a way of avoiding it without risk to other edge cases...
Comment #4
psynaptic commentedI do agree with you. Just need to find a more reliable solution.
Comment #5
nicholasthompsonI suggest that maybe open up an issue (with patch) against Views/Drupal Core which detects that if the menu callback matches a default action then redirect. I believe the same issue could apply to default menu callbacks...
Comment #6
niklp commentedAdd an access prevention rule to robots.txt, I would think?
Comment #7
nicholasthompsonThinking about this - maybe we could add a configuration page which allows toggling of this feature (trimming
/0off the end of the request)? Maybe 3 options...Comment #8
TonW commentedI think that its a good idea, adding a rule to robots would work too but i guess that 301 redirect is faster than robots if you want to remove a duplicated page.
Comment #9
chazz commentedI have been using that modified rule $request = trim($_REQUEST['q'], '/0'); but...
If i want to go for example to address that ends with 0 like http://mysite.com/taxonomy/term/30 then I will be redirected to http://mysite.com/taxonomy/term/3 ...
Same think if you like to edit your taxonomy term
instead of: admin/content/taxonomy/edit/term/30?destination=admin%2Fcontent%2Ftaxonomy%2F8%3Fpage%3D1
you will be redirected to admin/content/taxonomy/edit/term/3?destination=admin%2Fcontent%2Ftaxonomy%2F8%3Fpage%3D1
Is there any way to fix this ? Thanks
Comment #10
gregglesI agree with nicholasThompson in #7 that this should be optional. I kind of think this should default to off. It would cause really strange behavior that would be hard to debug - so if we make users turn it on then they'll hopefully remember it when their view is broken ;)
Comment #11
nicholasthompsonPatched in 5.x-dev. Will be in next main release.
http://drupal.org/cvs?commit=140018
Comment #12
gregglesWhat do you think about making it optional? I'd be willing to work on it if you don't have the time to do so. I think leaving /0 on the end should be a site specific thing.
Comment #13
nicholasthompson@greggles: It *is* optional :-)
I have added a toggle switch in the new Global Redirect Admin module bundles with the 5.x-dev release which allows users to switch certain features on and off such as de-slashing, non-clean to clean and the "/0" removal. It can be toggled between off (default), taxonomy term pages only and "all site".
Comment #14
niklp commented@nicholasThompson - you're going to patch this in the 6.x version today, right? :)
Comment #15
nicholasthompson@NikLP: I'd love to but I actually have a negative amount of free time at the moment. I was up till 1am last night doing the above fixes for 5.x and had to get up at 6.15am for work. I'm tired and busy today - not a good combo!
Cheersm
Nick
Comment #16
greggles@nicholasThompson - my bad. I obviously didn't look closely enough at the commit message.
Thanks for all your work.
Comment #17
chazz commentedThe new patch will fix issue from nr. #9 ? As I said before, The code above submitted by psynapic will delete all of the 0 in node address, not only one at the end.
Comment #18
niklp commentedNick, is it just a straight port that's required? If so, I will have a bash myself at some point.
Comment #19
nicholasthompson@chazz. The new feature has an option to enable it for taxonomy term URL's only. There should never be a "/0" argument to any nodes or terms. Not sure about block delta's though... I'll have a quick test to check to make sure "30" doesn't get truncated to "3"...
@NikLP: Its kind of a simple port - however I'd also like to include some of the custom_url_rewrite fixes over too. I'd certainly appreciated a hand with the process though :)
Comment #20
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #21
niklp commentedRe-opening because this isn't fixed in 6.x afaik.
Comment #22
greggles@nicholasThompson - do you have a real patch file for this? Digging them out of ViewVC at cvs.drupal.org has never worked well for me...which could mean we have to build this by hand.
Comment #23
nicholasthompsonI'll take a look... Cheers
(Sorry about the delay in responses at the moment... Combination of busy and my internet provider completely disconnecting me instead of upgrading me - easy mistake!)
Comment #24
nicholasthompsonIts a feature in 6.x-1.x-dev which is VERY shortly becoming 1.1.
By default the feature is disabled in the Global Redirect settings page to avoid any confusion with URL's on the site.