Archive for June 29, 2013

Saturday, June 29, 2013 [Tweets] [Favorites]

What Every Web Developer Must Know About URL Encoding

Stéphane Épardaud (via Ilya Grigorik):

This article describes common misconceptions about Uniform Resource Locator (URL) encoding, then attempts to clarify URL encoding for HTTP, before presenting frequent problems and their solutions.

For example:

This means that the “blue+light blue” string has to be encoded differently in the path and query parts: “”. From there you can deduce that encoding a fully constructed URL is impossible without a syntactical awareness of the URL structure.


The syntax of the URL is only meaningful before it is URL-decoded: after URL-decoding, reserved characters may appear.

Update (2013-07-13): Mike Abdullah mentions KSURLComponents, which can help with this.

Update (2013-07-16): Mike Abdullah:

But what if you want to programmatically construct a URL containing query parameters? Don’t worry, I’ve got your back again, with KSURLQueryUtilities. There you’ll find a selection of methods to go between URL (and their strings), and NSDictionary.

Update (2013-08-14): Mike Abdullah:

Most importantly, note the use of : characters in the example above. One is used after the brackets to indicate the port number. But what about this within the brackets? As we saw above, : characters must usually be escaped as part of a hostname, but for literal addresses, the brackets act as an exception to this rule.


For further complication, websites can make use of international domain names, whereby characters outside of the regular ASCII set are encoded using a system known as punycode. e.g. the domain exä is actually addressed as Web browsers take care of hiding this detail from users by presenting (and accepting) the unicode form of such domains. is a great way to view Web development reference materials (via webappstorm).