Percent encoding represents characters that have a special role or cannot be sent directly in a URL. Usually, encode an individual query value rather than blindly encoding an entire URL, so separators such as ? and & retain their meaning.
Encode the right part of a URL
A URL is made of components: scheme, host, path, and query. Encoding the whole string can turn structural punctuation into data and break the address.
- Identify the path segment or query value that contains special characters.
- Encode that component before inserting it into the URL.
- Leave URL separators and the trusted scheme and host intact.
- Decode a sample to confirm that the original value is recovered.
Keep in mind: A plus sign is interpreted as a space in form-style query encoding, but not in every URL context.