Mobile app version of vmapp.org
Login or Join
Nickens628

: Can punctuation inside a query string be valid? I'm still working on an apache module to fight google's ability to find duplicate content on my website and slashes are apparently throwing apache

@Nickens628

Posted in: #QueryString #Url

I'm still working on an apache module to fight google's ability to find duplicate content on my website and slashes are apparently throwing apache off.

My question is this. Is punctuation perfectly acceptable in the middle of a query string?

For example, would any of the following URLs be perfectly valid?
example.com/?/$=dollar http://example.com/?/=slash example.com/??=questionmark http://example.com/?//=twoslashes


Or do I have to convert them to URLs like this before requesting them and then making the receiving script decode them first?
example.com/?%3F=questionmark http://example.com/?%2F%2F=twoslashes example.com/?%2F=slash

I'm using CURL to make all my URL requests.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Nickens628

1 Comments

Sorted by latest first Latest Oldest Best

 

@Alves908

Is punctuation perfectly acceptable in the middle of a query string?


Yes, but it depends on the punctuation.

RFC 3986 Section 3.4 defines what characters are permitted in the query string part of the URL:

query = *( pchar / "/" / "?" )
pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
pct-encoded = "%" HEXDIG HEXDIG
sub-delims = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "="
ALPHA = (letters)
DIGIT = (decimal digits)


Adding all these together gives us the following characters that can be used unencoded:

A-Z, a-z, 0-9, -, ., _, ~, !, $, &, ', (, ), *, +, ,, ;, =, :, @ , /, ?

All other characters must be percent encoded.

However, a few of these characters have special meaning in the query string part of the URL. Notably &, + (encoded space), ; (alt to &) and =. So, if you need to include a literal one of these then it must also be percent encoded.

So, looking at your example:
example.com/?/$=dollar http://example.com/?/=slash example.com/??=questionmark http://example.com/?//=twoslashes


All these URLs are valid as-is (unencoded).

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme