On the World Wide Web, a query string is the part of a uniform resource locator (URL) containing data that does not fit conveniently into a hierarchical path structure. The query string commonly includes fields added to a base URL by a Web browser or other client application, for example as part of an HTML form.
A web server can handle a request either by reading a file from its file system based on the URL path or by handling the request using logic that is specific to the type of resource. In cases where special logic is invoked, the query string will be available to that logic for use in its processing, along with the path component of the URL.
A typical URL containing a query string is as follows:
http://example.com/over/there?name=ferret
When a server receives a request for such a page, it may run a program, passing the query string, which in this case is, name=ferret
unchanged, to the program. The first question mark is used as a separator, and is not part of the query string.
A link in a web page may have a URL that contains a query string. HTML defines three ways a user agent can generate the query string:
One of the original uses was to contain the content of an HTML form, also known as web form. In particular, when a form containing the fields field1
, field2
, field3
is submitted, the content of the fields is encoded as a query string as follows:
field1=value1&field2=value2&field3=value3...
While there is no definitive standard, most web frameworks allow multiple values to be associated with a single field (e.g. field1=value1&field1=value2&field2=value3
).
For each field of the form, the query string contains a pair field=value
. Web forms may include fields that are not visible to the user; these fields are included in the query string when the form is submitted
This convention is a W3C recommendation. W3C recommends that all web servers support semicolon separators in addition to ampersand separators to allow application/x-www-form-urlencoded query strings in URLs within HTML documents without having to entity escape ampersands.