URL encoding

[Updated: Feb 11, 2016, Created: Feb 11, 2016]


Also known as: Percent-encoding

URLs can only be composed of the restricted character set, which are a subset of ASCII characters.

ASCII characters like ASCII Control characters and ASCII reserved characters themselves cannot be used in URL.

There are situations where we have to use URL-restricted characters, for example in Query String and key value pairs of HTML form which are submitting to the server in message body.

Most commonly used restricted character is the white space, also we cannot used many characters like &, =, % etc. which are reserved ASCII characters.

URL encoding is the process of converting restricted characters to valid ASCII characters.

We don't have to necessarily do URL encoding manually.

All programming languages provide the support function.

  • JavaScript encoding function: encodeURI().
  • PHP encoding function: rawurlencode().
  • Java encoding static method: URLEncoder#encode()