Percent-encoding or URL Encoding is a mechanism to provide information in an URL under certain circumstances to ensure only certain ASCII characters are used. This is important for Application, Plugin development, SEO Purposes and for the Webmasters. Unfortunately enough, this Percent-encoding or URL Encoding is given much lesser weight than it deserves. Actually the peoples who are around the backbone of Internet are very less in number and with the advent of consumer grade Blogs ‘Popular’ blogs on Internet, these information are never passed to the general consumer or prosumer grade Internet Users. Without this Percent-encoding or URL Encoding some information could not be expressed in a URL. For example, a space in the browser usually interpreted as the end of the URL, the next following signs are ignored or cause an error. When we share an URL, for example you Retweet this article, they are converted to Percent-encoded or URL Encoded form. You can try by clicking the Twitter button below this article and notice the full set on address bar – its not necessary to hit the Retweet button, just observe the set in the pop up window. That is what Percent-encoding or URL Encoding we are talking about.
Percent-encoding and URL Encode/Decode : Basics
With URL encoding a space can be passed by the string %20. RFC 3986 defines a standard as a URI (and therefore also a URL) should be constructed syntactically and under what conditions the URL encoding is applied. The character which are not included in the ASCII character set, for the sake of representation, in URL encoding the percent sign used. There is however so far only one recommendation in RFC 3986, a mandatory standard is still missing. It is important to note the two phrases – Uniform Resource Locator (URL) and Uniform Resource Identifier (URI).
URL Encoding in fact, generally is more used within the main Uniform Resource Identifier (URI) set, which includes both Uniform Resource Locator (URL) and Uniform Resource Name (URN). As such, it is also used in the preparation of data of the application/x-www-form-urlencoded media type, as is often used in the submission of HTML form data or in HTTP requests. So, we need certain mechanism for the conversion. This is the basic principle behind Percent-encoding or URL Encoding.
---
Percent-encoding and URL Encode/Decode : Reserved and Non-reserved Characters
URLs can contain a maximum of the following fields:
1 | http://username:passwd @ www.example.net:8080/index.html?action=something&session=A54C6FE2 # info |
Certain characters identified within this expression and separate the various segments of the URL and allow disassembly and processing of expression. In a HTTP access, for example some processing like:
- Direction of the question mark (?) the data part ( query string ) of the URL
- Appending the equal sign (=) between the name of a parameter and its value
- Appending the ampersand (&) as delimiters between “parameter = value” elements in the data section
- Appending the hash (#) as the name of a document anchor (see also URI reference linked above)
are required.
Other characters have specific meanings in the document path . Altogether, the following characters are considered to be reserved:
1 | ! # $% & '() * +, /:; =? @ [] |
The following characters (groups) are not reserved, so have no predefined meaning in a URL:
1 | Letters [AZ, az], numbers [0-9] and - _. ~ |
However, the rules are not always strictly followed.
Percent-encoding and URL Encode/Decode : Tools
Now, coming to the practical part, the needed free tools for this percent-encoding and URL encode/decode work. PHP has own function :
1 | http://php.net/manual/en/function.rawurlencode.php |
This simply means, in WordPress or other CMS, we need not to depend on third party server, a plugin can make an URL suitable to be shared to Twitter (for example) by following the extra parameters needed to be added, thats why there is guide by Twitter :
1 | https://dev.twitter.com/docs/auth/percent-encoding-parameters |
But, these are actually never followed by the primarily Front End developers resulting in including too many Javascripts in the web pages. Here is a Command Line PHP based simple tool :
1 | https://github.com/AbhishekGhosh/URLize |
There are Java, Javascript, Ruby, Python, Apache Modules ways too.
Tagged With percent encoding , percent-encoding , url percent encoding , %IMAGEURL% , percent encode ampersand & , url to percent encoding dynamic parameter , online percent encode decode , long url percent encoding , interpreting percent encoding , how to url encode the percent sign in php