There are several characters on the URL which can not be transmitted over the internet. URL encoding helps to replace these characters with a “%” followed by two hexadecimal digits(ASCII code). The % indicates that after that the two digits are the encoded character.
To give you an example:
- Slash (‘/’) is encoded as "%2F"
- Plus ('+’) is also encoded as "%2B"
- Equal(‘=’) is also replaced as “%20”
URL encoding is necessary to process the request in a correct way by the web browsers or servers. If it is not being done properly, you might get unexpected errors from the web servers or browsers. However, modern web browsers are handling this automatically these days so you don’t have to do it yourself.
Example is:
Original URL:
https://example.com/search?q=green apples&category=fruits&price=2.99
Encoded URL:
https://example.com/search?q=green%20apples&category=fruits&price=2.99
Please also be aware of selecting the destination character set. UTF8 is one of the most popular ones and you can also clearly see in the selection box, which are popular sets and which are the others.
Common Use Cases for URL Encoding:
- Form Submissions: When submitting forms with special character, encoding needs to work correctly in the URL
- Email Links: When embedding URLs in emails, encoded URL helps to reduce the changes of link breaking.
- API Requests: For developers like us, when we send data in URLs during the API request, encoding helps all special characters handled correctly.
- Data Sharing: If you share URLs in the document, chat massages like what’s up, encoding helps that links remain
- If you’re sharing URLs in documents or chat messages, encoding makes sure links remain complete.