What is URL Encoding?
URL encoding, also known as percent-encoding, is a mechanism for encoding information in a Uniform Resource Identifier (URI). It ensures that all characters in a URL are from the limited set of ASCII characters allowed in URIs.
Why Encode URLs?
URLs can only be sent over the Internet using the ASCII character-set. Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format. URL encoding replaces unsafe ASCII characters with a '%' followed by two hexadecimal digits.
- / Used as a delimiter to separate path segments.
- ? Used to separate the path from the query string.
- # Used to separate the main URL from a fragment identifier.
- & Used to separate parameters in a query string.
- Spaces are not allowed in URLs and are often encoded as '+' or '%20'.
How It Works
URL encoding replaces reserved, unprintable, or non-ASCII characters with a percent sign (%) followed by a two-digit hexadecimal representation of the character's ASCII code.