What the three modes actually differ on
The confusing part of URL encoding is that there is not one of it. The rules change with where in the address the value is going to sit.
| Mode | Use it for | a/b?c becomes |
|---|---|---|
| Query value | One value going after ?q= | a%2Fb%3Fc |
| Whole address | A full line starting with https:// | a/b?c |
| Form post | What an HTML form sends as application/x-www-form-urlencoded | a%2Fb%3Fc, space as + |
The common mistake is running "query value" over a whole address. The
: and / in https:// get encoded too, you end up with
https%3A%2F%2F…, and the link is treated as a relative path.
Why one character turns into %C3%A9
Addresses may only carry ASCII. Anything else is split into UTF-8 bytes first, and each byte
becomes a % followed by two hexadecimal digits. An accented letter is two bytes, so
é becomes the six characters %C3%A9. Characters from non-Latin scripts
are usually three bytes, or nine characters each.
You can still type them straight into the address bar because the browser shows you the readable form while sending the encoded one. Copy that address into your code and you get the encoded version.
Is a space %20 or +?
Both are right, in different places. In a path (/my%20file) it must be
%20, and a + there is a genuine plus sign. Only in a form-post body and
in a query string is + read as a space. When in doubt use %20 — it is
understood in both.
What if I encode an already-encoded value?
The % becomes %25 and you have double encoding. If you see
something like %25C3%25A9, that is what happened, and
URL Decode has to run twice to get the original back.
Can I convert several lines at once?
Yes. Line breaks are left alone and each line is encoded separately, so you can paste a whole list.