views:

417

answers:

6

Why do so many Ruby on Rails apps have missing trailing slashes in their URLs? One example is http://basecamphq.com/tour. AFAIK this goes against Web standards. Is it something to do with the way RoR is set up?

+2  A: 

Because trailing slash denotes a directory, and you are not accessing directories in Rails, but pages. It's like tour.html in your example, except that .html can be ignored as it is the default.

+1  A: 

I'd venture to say that since in RoR, the URL you type usually does not map to a static file in a directory, but is resolved dynamically by the routes.rb file, ending the path with a trailing slash doesn't make much sense.

JRL
+7  A: 

It's not against Web standards. http://basecamphq.com/tour is considered a file, http://basecamphq.com/tour/ would be a directory (Note: both URLs aren't equal, although some webservers - e.g. Apache - will check the other if one doesn't exist). As both are kind of virtual, it's mainly up to the developer to decide (this is independent of used programming languages or frameworks).

I don't think it has something to do with caching (as mentioned by nilamo) as there are enough HTTP headers for cache control - might be that some reverse proxies have different default behavior though.

sfussenegger
Thanks, my understanding of the standard was clearly wrong.
Andrew
A: 

Some like slashes, some don't. Impassioned arguments can be made for both sides.

kaleissin
+4  A: 

Your argument is invalid:

w3c's url spec doesn't enforce trailing slashes on urls.

This is what it says about slashes:

The path is interpreted in a manner dependent on the scheme being used. Generally, the reserved slash "/" character (ASCII 2F hex) denotes a level in a hierarchical structure, the higher level part to the left of the slash.

Rails adheres quite well to this directive.

My hair is a bird!

egarcia
Fair enough, thanks for the info.
Andrew
A: 

This is a form of URL Re-writing. It is not against web standard and actually does a lot for usability and has been proven to help your search engine rankings. Think of it this way.

You are telling your friend about this cool post you seen on someone's blog. Which URL is easier to tell your friend:

  1. http://www.coolwebsite.com/post.aspx?id=aebe6ca7-6c65-4b5c-bac8-9849faa0a467

OR

  1. http://www.coolwebsite.com/cool-ideas-for-posts/
GaryDevenay
I'm not sure that this really addresses the question at hand. It mentions it's "url re-writing" but then provides an example URI ending in a slash. The question was why are they missing trailing slashes sometimes.
coderjoe