equality
and identity
are not identical, but they may be equal under certain circumstances. let me explain. identity claims that you are talking about the same thing (let's not delve into philosophical ontology here). equality claims that for given circumstances or constraints, two non-identical things are considered equal. equality always is based on a certain perspective, it never is a context-free relationship of two entities.
consider a web service that accepts queries and then lists items matching the query. let's assume you can query by color and by material. http://example.com/items?color=clear&material=carbon returns a representation of all clear-coated carbon items. http://example.com/items?material=carbon&color=clear probably does the same. are these two URIs identical? are they equal? or none of the above?
the URIs are clearly not identical because they are different, nothing in the URI's definition of a query string tells us that parameters sequence is insignificant. in fact, the URI spec does not even mention parameters, this is something that evolved out of how HTML form submission works, but this is specific for processing HTML form parameters and thus does not generally apply to URIs. it would be possible (but not very smart) to design a service only accepting one of these two URIs, and rejecting the other one. this would be like going to a store and asking where are the black shirts?
and getting a blank stare, and then asking do you have shirts which are black?
and then being happily served. this is not a very well-designed service. so at the very least both URIs should be accepted, but should they be processed identically (which would make them equal)?
if the URIs are not identical, are they equal? that depends on the context. if the query is interpreted as a logical and
, then it is commutative, and at least the returned items should be the same. however, it might still be assumed that the order of the parameters is significant, for example for deciding how the result page is formatted; or maybe there are more complex search functions and the UI allows to always remove the last search term. in these cases, the URIs are not even equal, even though they might return the same items.
the core question really is that of the service behind the URI. if anything in that service makes query parameter order significant, then the URIs should not be considered equal. on the other hand, the URIs could still be considered equal, and the additional information about the search term order could be handled using other web mechanisms such as cookies. this only works, though, if the additional information is considered secondary and transient, and thus should not be represented in the URI.
if we want to treat query parameter order as insignificant, how do we respond to both URIs? in an ideal implementation, the server accepts both URIs, but applies some URI canonicalization, and then redirects requests to the canonical form. this is good practice because it encourages clients to use the canonical form, which improves the ability to for example cache results, without the cache having to know that there are different variants of equal URIs.
to summarize: if there are different variants of URIs, think about whether they are equal (i.e., they can be substituted for each other without causing undesirable side-effects). if they are equal, define a canonical form and redirect to the canonical form, so that clients can still use the variants, but are encouraged to use the canonical form. this helps to reflect the fact that ideally, only identical URIs should be used for the same resource, but that due to syntax variations, it is possible to have different URIs which still should be processed identically.
Be liberal in what you accept, and conservative in what you send.
Jon Postel, RFC 1122