Squeaky Clean URLs

by Theresa O’Connor on 12 October 2006

Brad asks, can URLs be too clean? Specifically, he looks at two different styles of search URLs:

Form A
Form B

I suspect people are drawn toward form B because they want "search results for 'foo bar'" to unambiguously be a resource on the web. They don’t want to have one, generic "search" resource which takes on many different forms depending on whatever parameters are passed in.

Such a (perfectly admirable and reasonable) desire stems from a misunderstanding of what the query component of a URL actually is. Consider the definition of the query component in RFC 3986 (emphasis mine):

The query component contains non-hierarchical data that, along with data in the path component (Section 3.3), serves to identify a resource within the scope of the URI’s scheme and naming authority (if any).

So I think form A addresses the concern which appears to motivate form B.

Relatedly, here's a nice post from Mike Schinkel on how well-designed URLs are beautiful.


  1. I'm for Form B.

    I hate RFC's trying to tell me what to do.

    nate, 12 October 2006

  2. I like Form A for verb/action resources, and Form B for noun/object resources (roughly). To me, a query means "do something" and a non-query URL means "identify/fetch something". The former is also more likely to change than the latter.

    So for 'search' I'd go for A, but for 'product' I'd use B.

    Fortunately, that also happens to be roughly what Google and what other search engines, if they're still around, probably do — they don't index things that don't look like "things".

    So it seems that I differ from the RFC too, but for different reasons. I'd prefer 'example.com/products/pants' to 'example.com/products?name=pants'. However, I'd instead prefer 'example.com/products?id=42' to 'example.com/productsById/42'. Actually, perhaps the RFC and I don't differ that much after all, then, because the 'products/pants' example is really hierarchical — it would make sense to have 'example.com/products/pants/formal' and 'example.com/products/pants/jeans'. The 'id' example, on the other hand, is more of a property as it is unlikely you'd have any more layers of hierarchy on top of that. Same goes for a search, because what a search usually does is add more constraints ('product=pants&brand=Levis') rather than follow a hierarchy.

    Dan Moore, 12 October 2006