Understanding URL Query Strings

URL, short for Uniform Resource Locator, is web address that you see on web browsers.

You may have seen urls that look something like this.

http://website.com/page?example=this

The part after the question mark is a query string. It appears at the end of a URL and provides a way to send additional information that a web server can use to control the output of its response.

Generally a query string is used to search a database for information, and return a single record.

For example, if you want to send a link to a youtube video but you wish to start the video at a particular time you can forward the link as such:

www.youtube.com/watch?v=iAJhtHDwcS4#t=39m29s

Where v=iAJhtHDwcS4 after the question mark identifies which video to show from the youtube server and t=39m29s after # is the minutes and seconds the video will start from. The character # is used here to further specify a subsection (or fragment) of the video.

Query strings can hold multiple value pairs. Simply add an ampersand, followed by another 
name, an equal sign and another value.

http://website.com/page?field1=value1&field2=value2&field3=value3...

There are some requirements for query strings. 
Most importantly, you can’t just use any symbol you want in a query string. 
Some characters like the ampersand(&), equal(=), space( ), and
 quote marks(“”) have special meaning in a URL. 
So if you send information that includes
 those special characters you need to encode them.
That is, translate them into a set of symbols that 
are safe and don’t conflict with their URL specific version. 
For example, ampersand is represented by “%26”. 
A space is converted to a plus(+). 
And a plus is converted to “%2B”.

URL encode and decode is a website that can decode url query string symbols in case you are curious: http://www.url-encode-decode.com/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s