BL2.ru

Online urlencode, urldecode

This online urlencode / urldecode service lets you convert a string for use in links, or turn a string taken from a link back into a readable form.

What URL encoding is

A URL may contain only a limited set of ASCII characters. Everything else — spaces, Cyrillic, special characters — is written with percent-encoding: each byte is replaced with a % sign and two hex digits. For example, a space is %20 and & is %26.

Reserved characters

The characters : / ? # [ ] @ ! $ & ' ( ) * + , ; = have a structural meaning in URLs (they separate scheme, path and parameters). If such a character is part of a value it must be encoded: a&b=c/d? → a%26b%3Dc%2Fd%3F. Letters, digits and - _ . ~ are never encoded.

Non-ASCII and UTF-8

Non-ASCII characters are first converted to UTF-8 bytes, and each byte is encoded. A Cyrillic letter is 2 bytes, i.e. 6 characters:

InputURL-encoded
Привет мир%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82%20%D0%BC%D0%B8%D1%80
a b+c (in a form)q=a+b%2Bc
https://example.com/поиск?q=a bhttps://example.com/%D0%BF%D0%BE%D0%B8%D1%81%D0%BA?q=a%20b

+ or %20

A space is encoded in two ways. In a URL path only %20 is valid. In HTML form parameters (application/x-www-form-urlencoded) it is +, and a literal plus is then written as %2B. In PHP this is the difference between urlencode() (space → +) and rawurlencode() (space → %20).

encodeURIComponent vs encodeURI

  • encodeURIComponent() — for a single value (a parameter, a path segment): it also encodes / ? & =.
  • encodeURI() — for a whole URL: it keeps : / ? & = # and encodes only invalid characters.
  • Rule: always encode parameter values with encodeURIComponent, otherwise an & inside a value "breaks" the query string.

Where it helps

  • building links with parameters (UTM tags, search queries, redirect_uri in OAuth);
  • reading "unreadable" links from logs, the address bar and analytics;
  • debugging APIs and forms where a value was encoded twice (%2520 instead of %20).

How to use the page

  • Type text into the source field — the encoded string appears in the result field.
  • Paste a URL-encoded string into the result field — it is decoded into readable form.