Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Query string
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Structure == A typical URL containing a query string is as follows:{{quote|1=<code><nowiki>https://example.com/over/there?name=ferret</nowiki></code>}} When a server receives a request for such a page, it may run a program, passing the query string, which in this case is <code>name=ferret</code>, unchanged to the program. The question mark is used as a separator, and is not part of the query string.<ref>{{cite web | url = http://tools.ietf.org/html/rfc3986#section-3 | title = RFC 3986 | author = T. Berners-Lee | author2 = R. Fielding | author3 = L. Masinter | date = January 2005 | at = "Syntax Components" (section 3)}}</ref><ref>{{cite web | url = http://tools.ietf.org/html/rfc3986#section-3.4 | title = RFC 3986 | author = T. Berners-Lee | author2 = R. Fielding | author3 = L. Masinter | date = January 2005 | at = "Query" (section 3.4)}}</ref> [[Web Framework|Web frameworks]] may provide methods for parsing multiple parameters in the query string, separated by some delimiter.<ref name="w3c-recom" /> In the example URL below, multiple query parameters are separated by the [[ampersand]], "<code>&</code>": {{quote|1=<code><nowiki>https://example.com/path/to/page?name=ferret&color=purple</nowiki></code>}} The exact structure of the query string is not standardized. Methods used to parse the query string may differ between websites. 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: * an [[form (HTML)|HTML form]] via the {{tag|form}} element * a [[Image map#Server-side|server-side image map]] via the {{code|ismap}} attribute on the {{tag|img|open}} element with an {{tag|img|open|params=ismap}} construction * an indexed search via the now deprecated {{tag|isindex|open}} element === Web forms === One of the original uses was to contain the content of an [[form (HTML)|HTML form]], also known as web form. In particular, when a form containing the fields <code>field1</code>, <code>field2</code>, <code>field3</code> is submitted, the content of the fields is encoded as a query string as follows: {{quote|1=<code>field1=value1&field2=value2&field3=value3...</code>}} * The query string is composed of a series of field-value pairs. * Within each pair, the field name and value are separated by an [[equals sign]], "<code>=</code>". * The series of pairs is separated by the [[ampersand]], "<code>&</code>" ([[semicolons]] "<code>;</code>" are not recommended by the [[W3C]] anymore, see below). While there is no definitive standard, most [[web framework]]s allow multiple values to be associated with a single field (e.g. <code>field1=value1&field1=value2&field2=value3</code>).<ref>{{cite web|url=https://docs.oracle.com/javaee/6/api/javax/servlet/ServletRequest.html#getParameterValues(java.lang.String) |title=ServletRequest (Java EE 6 )|website=docs.oracle.com |date=2011-02-10|access-date=2013-09-08}}</ref><ref>{{cite web|url=https://stackoverflow.com/questions/1746507/authoritative-position-of-duplicate-http-get-query-keys |title=uri β Authoritative position of duplicate HTTP GET query keys|website=Stack Overflow |date=2013-06-09|access-date=2013-09-08}}</ref> For each [[Field (computer science)|field]] of the form, the query string contains a pair <code><var>field</var>=<var>value</var></code>. 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.<ref name="w3c-recom">[https://www.w3.org/TR/REC-html40/interact/forms.html#form-content-type Forms in HTML documents]. W3.org. Retrieved on 2013-09-08.</ref> In the recommendations of 1999, W3C recommended that all web servers support [[semicolon]] separators in addition to [[ampersand]] separators<ref>[http://www.w3.org/TR/1999/REC-html401-19991224/appendix/notes.html#h-B.2.2 Performance, Implementation, and Design Notes]. W3.org. Retrieved on 2013-09-08.</ref> to allow [[application/x-www-form-urlencoded]] query strings in URLs within HTML documents without having to entity escape ampersands. Since 2014, W3C recommends to use only [[ampersand]] as query separator.<ref name="w3c-recom-2014">{{cite web | url=https://www.w3.org/TR/2014/REC-html5-20141028/forms.html#url-encoded-form-data | title=4.10 Forms β HTML5 }}</ref> The form content is only encoded in the URL's query string when the form submission method is [[GET (HTTP)|GET]]. The same encoding is used by default when the submission method is [[POST (HTTP)|POST]], but the result is submitted as the [[HTTP request]] body rather than being included in a modified URL.<ref name="html5" /> === Indexed search === Before [[form (HTML)|forms]] were added to HTML, browsers rendered the β{{tag|isindex|open}} element as a single-line text-input control. The text entered into this control was sent to the server as a query string addition to a [[GET (HTTP)|GET]] request for the base URL or another URL specified by the {{code|action}} attribute.<ref>{{cite web |title=<isindex> |url=https://developer.mozilla.org/en-US/docs/Web/HTML/Element/isindex |website=HTML (HyperText Markup Language) |access-date=2015-11-21 |archive-date=2017-10-19 |archive-url=https://web.archive.org/web/20171019030835/https://developer.mozilla.org/en-US/docs/Web/HTML/Element/isindex |url-status=dead }}</ref> This was intended to allow web servers to use the provided text as query criteria so they could return a list of matching pages.<ref>{{cite web |title=HTML/Elements/isindex |url=https://www.w3.org/wiki/HTML/Elements/isindex |website=W3C Wiki |access-date=2020-03-20 |archive-date=2021-06-22 |archive-url=https://web.archive.org/web/20210622024419/https://www.w3.org/wiki/HTML/Elements/isindex |url-status=dead }}</ref> When the text input into the indexed search control is submitted, it is encoded as a query string as follows: {{quote|1=<code>argument1+argument2+argument3...</code>}} * The query string is composed of a series of arguments by parsing the text into words at the spaces. * The series is separated by the [[plus sign]], '<code>+</code>'. Though the {{tag|isindex|open}} element is deprecated and most browsers no longer support or render it, there are still some vestiges of indexed search in existence. For example, this is the source of the special handling of [[plus sign]], '<code>+</code>' within browser URL percent encoding (which today, with the deprecation of indexed search, is all but redundant with <code>%20</code>). Also some web servers supporting [[Common Gateway Interface|CGI]] (e.g., [[Apache HTTP Server|Apache]]) will process the query string into command line arguments if it does not contain an [[equals sign]], '<code>=</code>' (as per section 4.4 of CGI 1.1). Some CGI scripts still depend on and use this historic behavior for URLs embedded in HTML.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)