views:

32

answers:

1

The short question is - what is the best practice - to use or not to use a trailing slash in URLs.

There are many articles: this, this, this.

However, they all seem to deal with static directory structure. What about dynamic urls, like those rewritten, or those handled by a central facility (like a web framework, for example), that forward to internal resources depending on convention/configuration. For them it is no longer the case that the web server actually searches and figures out exact locations - it is just a matter of parsing.

So, for example with spring mvc you declare that a given class method is invoked when the URI matches /service/action/{pathParam} - for this URL, imo, it does not make sense to have a trailing slash - the request is handled by one and the same servlet each time, which does the parsing.

What I think is that one should just be consistent - either use trailing slashes everywhere, or don't use them at all.

So:

  • what's the best practice - with, without, or whatever-just be consistent
  • what's the reason to choose one over the other
+1  A: 
  • most important: stay consistant - 1 URL == 1 page
  • redirect one (wrong one) to the other (right one) via an HTTP 301 redirect (passes about 90% of link value)
  • then again if you have a website where different people work with: don't do trailings slashes.

i a perfect world people would just copy&paste an URL when they want to link to your stuff. sadly we do not live in a perfect world. people (i.e. pr guys, marketing) tend to typewrite URLs (don't ask my why, they just do....) and then again tend to forget the trailing slash at the end.

the wrong URLs in external links error rate is lower if you don't have trailing slashes.

but for most sites, it does not matter. choose one, stick with it.

Franz