Closed (duplicate)
Project:
Drupal core
Version:
7.x-dev
Component:
path.module
Priority:
Minor
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
24 Apr 2008 at 03:02 UTC
Updated:
8 Jul 2009 at 02:41 UTC
Jump to comment: Most recent file
Comments
Comment #1
KingMoore commentedThis same patch should work for 7x-dev.
Without patch:
function drupal_lookup_path("source", $path)
Will look up $path
With patch:
function drupal_lookup_path("source", $path)
Will look up $path, then if not found and $path does not end in a '/' it looks again for $path."/"
Comment #2
Crell commentedI don't see how this is desirable. Entering a path alias with a trailing slash is a user error. We should not be supporting user errors; we should be educating users away from them.
Comment #3
KingMoore commentedCrell,
There is some discussion about it here:
http://drupal.org/node/160753
The situation where this patch is needed is not a user error, but rather when the user wants a node to get a url_alias of something like 'my_node/' because they want this node to appear like an index page of a directory.
I don't think you should label this a user error because it is not the way you would structure a site. I believe Drupal should offer the site builder the flexability to put pages at locations like 'my_node/' if they want. If you read the discussion at above node, you will see users have various reasons for wanting to do this.
Thanks.
Comment #4
Rowanw commented-1
It's pointless to have a trailing slash, the only reason you'd need it is if you're converting from an old system that used trailing slashes. Even then, it's not worth breaking Drupal (for lack of a better term) just because other systems are broken.
KingMoore, you say that you'd use a trailing slash to indicate that the current page is a directory, but to who? Google won't treat it any differently, the server won't treat it any differently, a typical web-user certainly won't know what it means. It's just a meaningless character that takes up valuable space and requires an extra keystroke.
I've built sites for clients who didn't know they could type their site's domain name in the address bar of their browser, and it's their own website! Do you think these people care about whether or not there's a trailing slash?
And going by your use case, when you add a new sub page, are you going to change the parent page's URL to add a trailing slash even if it didn't have one before? If so, you risk creating a dead link. If you decide not to add a trailing slash this time then you're being inconsistent.
If you want to be old-fashioned then use Pathauto to add .htm to every node, and your categories will look like directories because they won't have an extension. You see, it's not a trailing slash that indicates a 'directory', it's the lack of a file extension.
Comment #5
KingMoore commentedMy point isn't that it is the best option in all situations, but that the site builder should have the flexibility to build his aliases as desired. Your arguments against structuring your site like this are good ones, however I don't see a real benefit doing it that way either. It is just that Drupal is currently restricted in this way, so there is a resistance to change, and would have to be an obvious benefit/reason for the change rather than just to provide more flexibility and options in configuring his/her site.
Upgrading an existing site structured in this way to Drupal is one huge example of where site builders want this flexibility. If you read the thread linked above, most of the people wanting this feature are people migrating sites from other systems, and don't want to risk deteriorating their rankings (even if temporarily) by switching to a system that can't preserve their old URLs w/out redirects. Multiple people looking to switch to Drupal have stated this as the main consideration for them NOT making the switch.
Comment #6
KingMoore commentedOn more thing to note:
Currently in Drupal (at least 5.7) you can create new content, and set the path alias to something like 'test/'. It will allow you to save the content and Drupal will give no errors. A new row is inserted into the {url_alias} table with a dst of 'test/'. However, this page will never be able to be accessed and after saving, the user will be given a 'page not found'.
If we aren't going to allow the system to work with aliases like 'test/', then the saving of them being permitted is certainly a bug. However, I would rather see them working after the save, than not saving at all.
Comment #7
macgirvin commentedI hate to be a jigger here, but with the patch as described, you'd be doing two lookups whenever a path wasn't available - and potentially before a 404 (let's take the case where the path just plain isn't there).
Why not..... just trim a trailing slash if it exists, and do a single lookup? Is there any place in Drupal where the trailing slash is valid and useful? If not, let's get rid of it. And I'm not suggesting we punish the poor user for typing it. They get punished enough. Just drop the thing quietly and return the page.
Comment #8
KingMoore commentedThat is what the system is currently doing. However if there is a path in the system that ends in a trailing slash (which the system does let you enter) then this path can never be found using current methods.
Comment #9
Crell commentedWell, then this becomes a bug report against Drupal 7, with intent to backport. Should be easy to do in the appropriate validate hook.
Comment #10
KingMoore commentedHis a new patch. It has been requested here: http://drupal.org/node/160753
It doesn't introduce an extra query. Note that if the path you are looking for is 'about/', drupal_lookup_path is actually sent just 'about' (the slash is stripped elsewhere and it would invove a much more complex patch to change that functionality).
The only downside of this patch is that you cannot have working paths in your system of both 'about' and 'about/'. Given that the original problem was that the Drupal allows saving of paths with a trailing slash, but then they could never be accessed, this is an improvement.
Here is an example of how it works, given the path 'about'.
drupal_lookup_path: 'about'
queries URL alias table for: 'about' or 'about/'
Return whatever comes back
If BOTH come back, only 'about' (without trailing slash) is returned.
Comment #11
j0hn-smith commentedsubscribing
Comment #12
KingMoore commentedI guess this should actually be a bug report as D5 allows you to save paths like 'about/', but drupal_get_path wont let you retrieve them.
Comment #13
drummHi, I am the Drupal 5.x maintainer, I do the final review for most patches going into Drupal 5.x. I appreciate your desire to get this patch into Drupal 5.x, but there have been some excellent reviews and you have simply pushed back. Please work with us and the issue will be resolved.
Path lookups happens a lot, one for each drupal-created link on the page, on every page request. Adding OR to the query does increase complexity, even a small performance loss might add up quickly. Benchmarks are necessary.
I am okay with adding a small amount of logic to the PHP code: removing trailing path slashes before lookup and ensuring paths are saved with slashes trimmed. In high-scalability situations, PHP load (more web servers) is much easier to handle than DB load (build out a database cluster).
Whenever multiple versions of Drupal need the same fix, we start with the highest and backport. The best code reviews happen on the more recent versions, and provide more opportunities for testing.
Comment #14
KingMoore commentedHi Drumm,
Thanks for your thoughtful response. I realize that the ability to save paths with a trailing slash will probably never make it into drupal core. I refined and reposted this patch specifically because multiple users have asked me to repost it because they do want that functionality.
The underlying issue for them (and myself) is that we be able to preserve and lookup paths with trailing slashes. Hence the suggestions to simply patch drupal core to not allow us to save paths with trailing slashes, while a valid bug that should be fixed, does not solve our problem (we can't currently use paths with a trailing slash and we want/need to).
I do have a hard time believing that adding an OR to an SQL query would produce a measurable performance loss.
Comment #15
j0hn-smith commentedA trailing slash may be technically incorrect however my company has thousands of pages with a trailing slash that rank well in google, we will not risk losing this ranking for anything. We simply wouldn't use Drupal or any other system that didn't allow us to use our current URLs. Many other companies/sites must be in a similar position.
Fundamentally, you should be free to choose any URL you like.
This issue will restrict drupal usage, surely we should remove barriers wherever possible. I think this functionality should be in core with, if necessary, an option in the admin pages to choose whether to allow the additional slash.
Comment #16
Bilalx commentedYou can check http://drupal.org/node/160753#comment-269946 and http://drupal.org/node/160753#comment-1127834 for a better solution
Comment #17
sammys commentedsubscribing
Comment #18
aaronnewton commentedPlease see my comment here -
http://drupal.org/node/203632#comment-1509768
which explains with practical examples and authority links which it is always a good idea to leave in trailing slashes.
Comment #19
dave reidThis is a duplicate of #103680: Path alias validation should test for full URLs