Designing URLs

Trailing slashes

According to RFC 3986 the following two URLs are not necessarily equivalent:

  • http://gigask.foo/organizations/3
  • http://gigask.foo/organizations/3/

But most users would think the two were equivalent. What's to be done? I think the RFC should have said that the first should be normalized to the second. However, working with the RFC as it is, we can issue a 301 (Moved Permanently) from http://gigask.foo/organizations/3 to http://gigask.foo/organizations/3/. Purists might object that a 301 is for a resource that used to exist but has moved, and http://gigask.foo/organizations/3 never did exist. I'm a purist but I don't think this use of 301 stretches its meaning too far.

Cool URIs don't change

Say we have to refer to organizations, we might have URLs like:

  • http://gigask.foo/organizations/sweb/
  • http://gigask.foo/organizations/centrica/
  • http://gigask.foo/organizations/eon/

This is the approach favoured in http://www-128.ibm.com/developerworks/library/us-cranky8.html. If Sweb undergoes a rebranding and the new name is EDF can make http://gigask.foo/organizations/sweb send a permanet redirect to:

http://gigask.foo/organizations/edf/

Some problems with this approach are:

  • If the URLs are maintained manually, it takes time / money for a diligent webmaster to remember to add the redirect.
  • If the URLs are for a web application, the web application software becomes more complicated, again costing time / money.
  • What if another company starts up with the name SWEB? (Unlikely with this example, but you can imagine it being a problem in other contexts).

These problems are solved with a scheme like:

  • http://gigask.foo/organizations/974563/
  • http://gigask.foo/organizations/67/
  • http://gigask.foo/organizations/879881/

This takes Cool URIs don't change to an extreme. The drawback is of course that URLs lose much of their meaning, but my view is that the tradeoff is worth it. Okay, so you've convinced my to use meaningless ids. What about using ISBN codes for books and license numbers for cars as my id?

Established ids in URLs?

The book 'Being And Nothingness' by Jean-Paul Sartre has ISBN 0671867806. If on my website I have reviews of books, should I use the ISBN?

http://gigask.foo/book-reviews/0671867806/

No, because I may have got the isbn wrong, and then the URI would have to change. Better to have a completely new id:

http://gigask.foo/book-reviews/2859783/

But what if I have the ISBN and I want to find the corresponding review on gigask.com? It should be possible to do a query like:

http://gigask.foo/book-reviews/?isbn=0671867806

This is the URL equivalent to the intelligent versus surrogate keys debate in SQL.

Comments