What is URL Encoding?
URL encoding is a process of converting certain characters in a URL to a format that can be transmitted over the internet or other network protocols without being misinterpreted or corrupted.
URLs are used to identify resources on the internet or other networks, and can contain various
characters such as letters, numbers, and symbols. However, some characters have special meanings
in
the context of a URL, such as the forward slash (/
) used to separate different
parts of
a URL,
or the question mark (?
) and ampersand (&
) used to pass parameters to
a
web server.
When a URL contains special characters, it must be encoded to ensure that it can be safely transmitted and understood by other computers and devices on the network. This is done by replacing each special character with a sequence of one or more characters that represent the character in a standardized way.
For example, the space character in a URL is typically encoded as %20
. So a URL like
https://example.com/search?q=hello
world be encoded as
https://example.com/search?q=hello%20world
URL encoding is typically used in web applications to ensure that URLs containing user-generated data are properly formatted and can be safely transmitted across different devices and platforms.
Which Characters Are Allowed in a URL?
The characters that are allowed in a URL depend on the context in which they are used. In general, a URL can contain the following characters:
- Alphanumeric characters (A-Z, a-z, 0-9)
- Special characters ($, -, _, ., +, !, *, ', (, ))
- Reserved characters (;, /, :, @, &, =, +, $, ,, %, #, [, ], ?, {, }, |, ^, \, ~, <, >, ", ')
- Non-ASCII characters, such as international characters and emojis, may be allowed in some contexts, but must be encoded using Unicode transformation format (UTF-8). However, some characters have special meanings in the context of a URL and must be encoded to be used as data. For example, the forward slash (/) and colon (:) are used to separate different parts of a URL and must be encoded if used in the data portion of a URL. Similarly, the question mark (?) and ampersand (&) are used to pass parameters to a web server and must also be encoded if used in the data portion of a URL.
Some characters in URL have special meanings and must be encoded when used in the URL to ensure that the URL is properly formatted and can be safely transmitted and understood by other computers and devices on the network.