5 min read
2026-01-28
URL encoding seems simple, but it often leads to mistakes. Here are the key tips.
Do not encode the entire URL. Only encode query parameter values, leaving the URL structure intact.
In the URL path, a space is encoded as %20. In form bodies (application/x-www-form-urlencoded) it is encoded as +. Do not confuse the contexts.
Double encoding is a common mistake. The & character becomes %26, and if encoded again — %2526. Always check your input data.
Cyrillic and other Unicode characters are first converted to UTF-8 bytes, then each byte is encoded separately.
In JavaScript, use encodeURIComponent() for encoding parameters, not encodeURI(). They encode different sets of characters.
Encoded URLs can become very long. Most browsers support URLs up to 2048 characters. For long data, use POST requests.
See also: Base64 Encoding, HTML Encoding, Binary Text