1

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?

http://example.com/?/$=dollar
http://example.com/?/=slash
http://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?

http://example.com/?%3F=questionmark
http://example.com/?%2F%2F=twoslashes
http://example.com/?%2F=slash

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

  • 1
    You can do what I do and write some sample code and test your theory. – closetnoc Aug 27 '15 at 4:34
  • closetnoc, testing is making my face blue but at least escaping the slash prevents apache from being thrown off. Now I just have to remember to tell all server clients not to use question marks or slashes as parameter names or parameter values of a query string. – Mike Aug 27 '15 at 4:36
  • I getcha. We have all been there. I found there is always an answer somewhere... it'll come to you after you're in bed and do want to get out to take notes- especially in the winter or a blonde close by. – closetnoc Aug 27 '15 at 4:40
  • Mike, if you're using mod_rewrite, I suspect any of them will work, depending on what pattern you are using to match your query string. – Meezaan-ud-Din Aug 27 '15 at 6:07
3

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:

http://example.com/?/$=dollar
http://example.com/?/=slash
http://example.com/??=questionmark
http://example.com/?//=twoslashes

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.