What is the difference between ; and & in a URL?

Asked

Viewed 1,768 times

25

I was watching a website to add in a C#application, I noticed a link similar to this:

www.site.com.br/index.php?post=yes;user=1521;

The parameters are separated by ;(semicolon). I accessed the same page changing the ;(semicolon) by &('and' commercial):

www.site.com.br/index.php?post=yes&user=1521

The page was loaded normally, there is some difference between ; and &?

  • 2

    In the title "web Forms" there is a basic explanation. https://en.wikipedia.org/wiki/Query_string

  • It is more common to see using & than ;

4 answers

10


In the commented link by @Bacco we have the following definition:

  • 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, '='.
  • The series of pairs is separated by the ampersand, '&' (or semicolon, ';' for Urls Embedded in HTML and not generated by a ...; see Below).

To sum up:

  • The query string consists of pairs of campos=valor
  • Each pair series is separated by &, or ; if it is not from a form.

However I would like to show the following:

If I access a URL like this :

www.site.com.br/index.php? post=yes|user=1521|pass=123|Uf=RS

www.site.com.br/index.php? post|yes|user|1521|pass|123|Uf|RS

You think it might not work?

The fact is that whatever comes after the ?, will usually be caught by GET of the language you are working on, and this information will be a string, how your code will interpret what comes will depend on your coding.

6

The semicolon character ; (alias "semicolon") can be used as a parameter separator in a URL. However, the ampersand character & is the standard per general convention.

The semicolon is a subdelimiter. The use is applicable in specific schemas. Example, the schema "Prospero":

prospero://<host>:<port>/<hsoname>;<field>=<value>

http://www.ietf.org/rfc/rfc1738.txt

Note that the comma , is also a valid separator, but under the same context because both are classified as subdelimitators, according to the rfc3986.

See also: http://tools.ietf.org/html/rfc3986#Section-2.2

1

The ; is reserved and can be used by servers for a type of data separation, as in your example clearly happens, while the & is usually used for separation of GET parameters. The ; may however have another use/meaning with another server, for example may have systems that use ; inside the back of & to separate several parts of the answer.

In practice it has relatively few standard server software, and within each of these it can have a relatively uniform treatment of these symbols. However, each yes server has every right to use these symbols as it best serves the running application, so there is no guarantee that & and ; will always be equivalent.

In your case you use C# and the default API seems to treat everything the same. But because in C# you can create your own style of handling everything, even here it’s 100% guaranteed. That’s just because it’s preset like this.

More relevant information: https://stackoverflow.com/questions/2163803/what-is-the-semicolon-reserved-for-in-urls

0

Briefly that’s what:

If you use & or ; in query string generated by the code itself (HTML, or JS) for parameter separation.

However, the & can be used also in query string generated by a FORM, already the ; nay.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.