What is percent-encoding?
coffee beans & tea → coffee%20beans%20%26%20tea кафе → %D0%BA%D0%B0%D1%84%D0%B5
What gets encoded.
Space
%20, or + inside a query string.
Ampersand &
%26, because it separates parameters.
Equals =
%3D, because it separates name and value.
Question mark ?
%3F inside a value, because it starts the query.
Hash #
%23, because it starts the fragment.
Non-ASCII letters
Encoded as their UTF-8 bytes, one %XX for each byte.
Encode values, not the whole URL.
Encode each parameter name and value before joining them. Encoding a whole URL also encodes the colons and slashes that make it a URL. The query string builder and the URL encoder handle this correctly.
Common questions
Is a space %20 or +? +
Both work inside a query string. %20 works everywhere in a URL, + only in the query.
Why do browsers show some URLs unencoded? +
Address bars decode them for readability. The encoded form is what is sent.
Does encoding change where a URL points? +
No. It only changes how characters are written. Servers decode them before use.
What is double encoding? +
Encoding an already encoded value, so %20 becomes %2520. It is a common bug and usually breaks the link.