Search code examples
phpurlurl-encoding

What bad things happens to me if I don't url-encode backslashes in query calls?


I know php's http_build_query() url-encodes backslash-characters in the query string. I also know that the backslash is a reserved character, making this the desired behavior for that function. I have seen people I respect as programmers use unencoded backslashes in their query strings, and have been wanting to do the same to make my urls look a little nicer. What bad things (if any) do I have to expect when refraining from url-encoding my backslashes?

The reason I even started to think about breaking the url-encoding conventions is the fact that google uses plusses in their query strings. Does anyone know what bad things happen to THEM for doing that?

The problem I am ultimately trying to solve is to somehow delimit my ?q=MVC calls with a humanly legible, url-safe character, without having to set more than one query variable.


Solution

  • The RFC is pretty clear about this:

    query = *( pchar / "/" / "?" )

    The characters slash ("/") and question mark ("?") may represent data within the query component. Beware that some older, erroneous implementations may not handle such data correctly...

    So it's fine to use slashes in the query part (unless you have to deal with implementations that were "older" back in 2005).