Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is question mark in URL part of query string?

TL;TR: Is (first) question mark in URL part of query or is is just a separator followed by query?

The RFC 1738, section 3.3, suggests that the "?" (question mark) is not part of the query string, but just separates it from the path:

http://<host>:<port>/<path>?<searchpart>

Grammar presented in the RFC 3986, Appendix A., also indicate the "?" is not part of the actual query string:

URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]

Now, let's consider two URLs:

  1. http://server.com/api/item.json
  2. http://server.com/api/item.json?

Are they equivalent or distinct?

Is it valid to distinguish them and use to identify two different resources?

like image 833
mloskot Avatar asked Dec 04 '15 22:12

mloskot


People also ask

Does query string include question mark?

In a URL, the query starts with a question mark - the question mark is used as a separator, and is not part of the query string. If you also include a question mark in the query string, this would be treated as a literal question mark (i.e. it has no significance beyond that of a regular character).

What is question mark in query string?

Query strings The question mark ("?", ASCII 3F hex) is used to delimit the boundary between the URI of a queryable object, and a set of words used to express a query on that object. When this form is used, the combined URI stands for the object which results from the query being applied to the original object.

How can I tell if a URL has a query string?

Use Regex to check a given URLcharacter and querystring name/value pair. If yes, the URL definitely contains a query string and vice versa. You can see live version of this approach here by clicking on the “Run Example” button.

What part of the URL is the query?

On the internet, a Query string is the part of a link (otherwise known as a hyperlink or a uniform resource locator, URL for short) which assigns values to specified attributes (known as keys or parameters). In the above example the question mark separates the base URL from the Query strings.


1 Answers

tl;dr:

  • The ? is not part of the query component.
  • The URIs are not equivalent, because one has no query component, while the other one has an empty query component.

The URI standard (STD 66) is currently RFC 3986.

Section 6.2. Comparison Ladder describes methods how to test if URIs are possibly equivalent.

In 6.2.3. Scheme-Based Normalization it says:

Normalization should not remove delimiters when their associated component is empty unless licensed to do so by the scheme specification. For example, the URI http://example.com/? cannot be assumed to be equivalent to any of the examples above.

Where "examples above" refers to:

http://example.com
http://example.com/
http://example.com:/
http://example.com:80/

(These 4 URIs are equivalent.)

So http://example.com/api/item.json has no query component, while http://example.com/api/item.json? has an empty query component.

like image 150
unor Avatar answered Oct 20 '22 00:10

unor