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?

CommentFileSizeAuthor
globalredirect.module.patch569 bytespsynaptic

Comments

nicholasthompson’s picture

Status: Needs review » Needs work

i 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"...

psynaptic’s picture

Is there anything in the system that would allow us to be sure we're trimming only the unwanted /0's?

nicholasthompson’s picture

Status: Needs work » Postponed

Not 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...

psynaptic’s picture

I do agree with you. Just need to find a more reliable solution.

nicholasthompson’s picture

I 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...

niklp’s picture

Add an access prevention rule to robots.txt, I would think?

nicholasthompson’s picture

Status: Postponed » Postponed (maintainer needs more info)

Thinking about this - maybe we could add a configuration page which allows toggling of this feature (trimming /0 off the end of the request)? Maybe 3 options...

  1. Disabled
  2. Enabled for taxonomy/term paths only (default)
  3. Enabled for all paths
TonW’s picture

I 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.

chazz’s picture

I 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

greggles’s picture

Priority: Minor » Normal
Status: Postponed (maintainer needs more info) » Needs work

I 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 ;)

nicholasthompson’s picture

Status: Needs work » Fixed

Patched in 5.x-dev. Will be in next main release.

http://drupal.org/cvs?commit=140018

greggles’s picture

What 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.

nicholasthompson’s picture

@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".

niklp’s picture

@nicholasThompson - you're going to patch this in the 6.x version today, right? :)

nicholasthompson’s picture

@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

greggles’s picture

@nicholasThompson - my bad. I obviously didn't look closely enough at the commit message.

Thanks for all your work.

chazz’s picture

The 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.

niklp’s picture

Nick, is it just a straight port that's required? If so, I will have a bash myself at some point.

nicholasthompson’s picture

@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 :)

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

niklp’s picture

Title: Patch for taxonomy/term/tid/0 URLs » Patch for taxonomy/term/tid/0 URLs in D6 version
Version: 5.x-1.2 » 6.x-1.x-dev
Status: Closed (fixed) » Active

Re-opening because this isn't fixed in 6.x afaik.

greggles’s picture

Status: Active » Patch (to be ported)

@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.

nicholasthompson’s picture

I'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!)

nicholasthompson’s picture

Status: Patch (to be ported) » Fixed

Its 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.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.