Reputation: 3029
We all know there are 2 delimiters for query strings. Which are ?
and &
. Why wouldn't we use just ?
for both cases? Why do we need &
RFC 3986 gives description of the standard, but does't provide us with motivation on that subject.
The query component is indicated by the first question mark ("?") character and terminated by a number sign ("#") character or by the end of the URI.
Upvotes: 0
Views: 134
Reputation: 718678
If you read the various URL specifications, you will see that it doesn't set out any syntax for the <query>
component. Indeed, the client and server could agree on any syntax for the string subject to the restrictions on allowed / reserved characters.
The ?<name>=<value>&<name>=<value>
syntax that is most commonly used comes from the HTML specification. Look for the section of the HTML spec (pick any version) that specifies the "application/x-www-form-urlencoded" encoding scheme for form parameters.
Why does the HTML spec not use &
as the parameter separator? I think that is because the URL spec says that ?
is reserved in the <query>
part. (So if HTML used ?
as a separator, it would need to be percent-encoded.)
Why is ?
reserved in the <query>
part? Well now we are getting into the history of http:
hyperlinks before a unified URL specification existed. Basically, I don't know, but it could have been related to the way that early web servers or browsers parsed hyperlinks.
Upvotes: 1