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
Comment #1
hass commentedi 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".
Comment #2
Anonymous (not verified) commentedIt 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.
Comment #3
hass commentedI 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.
Comment #4
nicholasthompsonThe 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.
Comment #5
nicholasthompsonI dont think this is a bug as such - its by design...
Comment #6
hass commentedAnd 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:
Correct?
About the IN () statement i think same... Drupal 6 may do the trick as i have seen...
Comment #7
hass commentedanother 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.
Comment #8
nicholasthompsonI 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.
Comment #9
hass commentedLet 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."
Comment #10
nicholasthompsonVery 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
Comment #11
nicholasthompsonThis is fixed in the updates I applied today to al branches (EXCEPT HEAD - this is a TODO).
Comment #12
killes@www.drop.org commented