45

Are there any naming conventions or standards for Url parameters to be followed. I generally use camel casing like userId or itemNumber. As I am about to start off a new project, I was searching whether there is anything for this, and could not find anything. I am not looking at this from a perspective of language or framework but more as a general web standard.

Andrew Tobilko
  • 44,067
  • 12
  • 74
  • 128
Dinesh Manne
  • 1,684
  • 6
  • 23
  • 32
  • The general trend is to remove technology details from the URL such as `.php`. Besides that people come up with all kinds of "semantic" URL structures. It does not matter much. – usr Oct 11 '17 at 16:29

6 Answers6

18

I recommend reading Cool URI's Don't Change by Tim Berners-Lee for an insight into this question. If you're using parameters in your URI, it might be better to rewrite them to reflect what the data actually means.

So instead of having the following:

/index.jsp?isbn=1234567890
/author-details.jsp?isbn=1234567890
/related.jsp?isbn=1234567890

You'd have

/isbn/1234567890/index
/isbn/1234567890/author-details
/isbn/1234567890/related

It creates a more obvious data structure, and means that if you change the platform architecture, your URI's don't change. Without the above structure,

/index.jsp?isbn=1234567890

becomes

/index.aspx?isbn=1234567890

which means all the links on your site are now broken.

In general, you should only use query strings when the user could reasonably expect the data they're retrieving to be generated, e.g. with a search. If you're using a query string to retrieve an unchanging resource from a database, then use URL-rewriting.

David Grant
  • 13,235
  • 3
  • 52
  • 62
  • 72
    This doesn't answer the question at all. The original post was asking if there was a naming convention for query string parameters. As you mentioned yourself, query strings are appropriate when you are searching through or filtering the data (http://stackoverflow.com/a/17999251/1424734), so why the tangent on their proper use? – jstol Sep 11 '14 at 17:15
  • 5
    Please answer the question on camel case vs hyphenated naming of querystring parameters instead – zwolin Dec 11 '18 at 12:46
8

There are no standards that I'm aware of. Just be mindful of IE's URL length limit of 2,083 characters.

John Topley
  • 107,187
  • 45
  • 188
  • 235
7

Standard for URI are defined by RFC2396.
Anything after the standardized portion of the URL is left to you.

You probably only want to follow a particular convention on your parameters based on the framework you use.
Most of the time you wouldn't even really care because these are not under your control, but when they are, you probably want to at least be consistent and try to generate user-friendly bits:

  • that are short,
  • if they are meant to be directly accessible by users, they should be easy to remember,
  • case-insensitive (may be hard depending on the server OS).
  • follow some SEO guidelines and best practices, they may help you a lot.

I would say that cleanliness and user-friendliness are laudable goals to strive for when presenting URLs.
StackOverflow does a fairly good job of it.

Renaud Bompuis
  • 15,947
  • 4
  • 51
  • 81
  • I agree with you on the style of urls, and avoiding the parameters, i was interested in this style first when i saw Atlassians's Jira and Bamboo have it, made url's look simple. On Apache it can be set up with some rewrite rules. Do you know anything similar for IIS and .NET – Dinesh Manne Feb 21 '09 at 13:48
  • According to [RFC 3986, 6.2.2.1](http://www.ietf.org/rfc/rfc3986.txt): *other generic syntax components are assumed to be case-sensitive*. So why generate case-insensitive bits? – Martijn Burger Aug 03 '17 at 07:13
  • 1
    @MartijnBurger because a end-user manually entering the URL may not expect that a string be case-sensitive. Principle of Least Surprise and all. – Renaud Bompuis Aug 03 '17 at 11:38
3

I use lowercase. Depending on the technology you use, QS is either threated as case-sensitive (eg. PHP) or not (eg. ASP). Using lowercase avoids possible confusion.

vartec
  • 118,560
  • 34
  • 206
  • 238
2

Like the other answers I've not heard about any conventions.

The only "standard" I would adhere to is to use the more search engine friendly practice of using a URL rewriter.

Iain M Norman
  • 2,047
  • 15
  • 30
0

There are no standards that I know of, and case shouldn't matter.

However within your application (website), you should stick to your own standards. For your own sanity if nothing else.

Jeremy French
  • 10,555
  • 4
  • 43
  • 68