URL Encoding Rules: Reserved Characters and Percent-Encoding

Which characters must be percent-encoded, the difference between encodeURIComponent and full-URL encoding, and query vs path rules.

Reserved and unsafe

RFC 3986 reserves : / ? # [ ] @ ! $ & ' ( ) * + , ; =. Bytes above 0x7F and control characters must be encoded. Percent-encoding writes each byte as %XX after UTF-8 encoding the character.

Component vs whole URL

encodeURIComponent escapes everything meaningful in a URL, so it is right for parameter values but wrong for a whole URL (it would destroy its structure). The URL encoder here offers both modes explicitly.

Spaces: %20 vs +

Path segments use %20. In query strings, application/x-www-form-urlencoded uses + for space. Both decode fine in modern parsers, but emit the form your consumer expects.

相關工具