Which characters get encoded
A URL may only contain a limited set of ASCII characters. Anything else is written as % followed by the byte in hex. A space becomes %20, and a non-ASCII character becomes one %XX group per UTF-8 byte, so “é” is %C3%A9.
| Choice | Leaves alone | Use it for |
|---|---|---|
| A value | A-Z a-z 0-9 - _ . ! ~ * ' ( ) | One query value or path segment |
| A whole URL | The above plus ; / ? : @ & = + $ , # | A complete address that should stay usable |
Encoding a whole URL as a value turns :// into %3A%2F%2F. That is right when the URL is itself a parameter, as in a redirect target, and wrong otherwise.
Plus signs and spaces
HTML forms encode a space as +. Plain percent-encoding uses %20, and a + there is a real plus sign. Tick “Spaces as +” when you are working with form data or a query string built by a form.
Questions
Why does decoding fail on a single % sign?
A % must be followed by two hex digits. Text such as “50% off” was never encoded. Encode it first, or write the sign as %25.
Why are the decoded characters wrong?
The bytes were probably encoded from a character set other than UTF-8. Older sites used the local encoding of their country.
Should I encode twice to be safe?
No. Double encoding turns %20 into %2520, and the receiving side will show a literal “%20”.