please do not call twice... there is realy enough DB transaction to this alias table (!!!)...

you are able to test if the last char in URL is a "/" and if so remove first or do nothing if no "/", and after all of this string cleanup - call drupal_get_path_alias();

thank you.

Comments

hass’s picture

i wonder why you are checking for "/" on the end of an URL... it is is "not possible" to add a alias with a slash on the end. if someone do, it will not work everytime... i've done this mistake in past, and learned drupal isn't working well if a slash is attached to the URL... while this creates incompatible URLs in Microsoft IIS (tested again some minutes ago). it will crash the page while it ends with an URL http://localhost/drupal/index.php?q=example/ and as you can see you get a slash in an URL param, what is wrong!

So you should mark request for such a feature as "won't fix" or "by design".

Anonymous’s picture

It is possible to use / as an ending character in the URL if ``Clean URLs'' is turned on. For example, http://give-me-an-offer.com/offers/deptstores/ is one of my URL's that will work with an ending slash. Or am I reading what you are trying to say incorrectly.

Yes the example URL is a promotion landing page but it is a live example of a site using Global Redirect.

hass’s picture

I know this works with clean URL, but this is not a way how you should name URLs in Drupal. It breaks compatibility and therefor this is not correct. I think this will end in Apache with a URL param including a slash, too - and as i said - this is wrong... it more something like a small wonder, that it works... i think.

You may better use mod_rewrite or something like this in such a case, not tested... but implementing such a feature in a module is wrong from drupal side.

nicholasthompson’s picture

The reason I do this test is as follows...
http://drupal.org/node/105275
http://drupal.org/node/105275/

Both those URL's point to the same page - EXACTLY the same page. This is VERY bad from an SEO point of view as the search engine will assume the first page is at level 2 depth and is a page called 105275 whereas second page is at level 3 depth and using the default index page (ie, 105275 has turned from a file to a folder).

The reason I do an alias lookup check is that you might type in node/105275/ which WILL NOT be picked up by the alias lookup as it has a slash on the end. If a slash is present and no alias matches then its essential we strip the slash and check THAT URL for a match too...

I agree that people/module's shouldn't do this - however people, in the general public, are stupid and will add all kinds of dots and slashes to URL's. All it takes are two silly bloggers to link to a page on your site - one with a trailing slash and one without - and you have instantly produced duplicate content on your site which takes you one step closer from getting banned off google thus costing you traffic and therefore, usually, money.

One thing I would like to see in Drupal is the ability to do a multiple alias lookup in 1 query. You could do a test in the function. If you provide a string to drupal_get_path_alias then do a single lookup, but if you have an array, do an "IN()" comparison on the query.

nicholasthompson’s picture

Status: Active » Closed (works as designed)

I dont think this is a bug as such - its by design...

hass’s picture

And what will you do if i'd ask you - for some other stupid people - for .html and htm extension and so on? will you implement this too? I think - if a URL is correct, it is - if not - it is not. Building this inside a module makes no sense. If I know my website and i'm implementing a simple mod_rewrite rule in my .htaccess. for e.h. if a slash is on the end of my URL, remove this and redirect to the same node without a slash - this is - highest performance you can get and do not require to add additional senseless DB request.

What you do is somewhat different as i have seen:

  1. do a alias lookup to node/12345 to get "test/example"
  2. alias not found and do not exist for this url - this can really happen - if there is no alias for every node
  3. we haven't found an alias, we do another request, maybe there is a chance to fine a url with a slash (*maybe*)
  4. another time - nothing will be found, while i have clean drupal urls and don't name my URLs internally with slashes on the end.
  5. so there happen 2 alias table request without any result.

Correct?

About the IN () statement i think same... Drupal 6 may do the trick as i have seen...

hass’s picture

another idea is - if you don't like mod_rewrite - remove the slash of an incoming URL via regex containing a slash and redirect to non slash URL btw. do the lookup with non slashes. This is possible, while you know your site url's are build technically correct without slashes on the end.

nicholasthompson’s picture

I will make slash checking an optional extra in a settings area. I can see your point that it might not always be necessary - but sometimes you might want it.

hass’s picture

Status: Closed (works as designed) » Active

Let me reopen this issue, please. Have a look to this drupal core translation... it will tell you - you should never add slashes to the end of a drupal URL. Therefor the module should remove every trailing slash if coming in and do a lookup then. nothing else... and no double checking as today.

#: modules/path/path.module:192
msgid "Specify an alternative path by which this data can be accessed. For example, type \"about\" when writing an about page. Use a relative path and don't add a trailing slash or the URL alias won't work."

nicholasthompson’s picture

Very true - Rob Douglass has just submitted a patch to neaten the code up and it does one lookup on the source url and thats without the slash.

I also noticed the other day about not using a slash in source url's for aliases...

This will get committed.

Thanks hass.

Nick

nicholasthompson’s picture

Assigned: Unassigned » nicholasthompson
Status: Active » Fixed

This is fixed in the updates I applied today to al branches (EXCEPT HEAD - this is a TODO).

killes@www.drop.org’s picture

Status: Fixed » Closed (fixed)