Parts of URL

Parts of URL

We see so many URLs everyday, but do we know what are the parts of an URL, what does each part means? In this post I will discuss the various parts of the URL.

An URL may consists of as many as 6 parts. The different parts of the URL are:

scheme://domain:port/path?query_string#fragment_id

Some people refer to the parts as:

protocol://hostname:port/pathname?search#hash

Just to easily remember the different parts, I normally refer the URL as

protocol://domain:port/path?query_string#hash

Now lets see what each part means.

Part Meaning Required
scheme or protocol Internet protocol to be followed. e.g. http, https, ftp, mailto, etc. This defines the syntax of the URL. Yes
domain or hostname This is the destination location for the URL. It can be a hostname or ipaddress. Yes
port The port to be used to connect to the location. No
path or pathname This is typically a file or location on the web server. No
query_string or search This is the data to be passed to software running on the server. No
fragment_id or hash This specifies a part or a position within the overall resource or document No

Lets see a few example URLs to understand what are the different paths of the URL.

Example 1:
http://www.example.com/
This URL consists of only 2 parts. They are:

protocol http
domain www.example.com

Example 2:
http://www.example.com:80/example.php?x=1&y=2#results
In this URL the different parts are:

protocol http
domain www.example.com
port 80
path example.php
query_string ?x=1&y=2
hash #results

Example 3:
http://www.example.co.in:80/example.php?x=1&y=2#results
In this URL the different parts are:

protocol http
domain www.example.co.in
port 80
path example.php
query_string ?x=1&y=2
hash #results

Lets analyse the example 3 in more detail
The URL is http://www.example.co.in:80/example.php?x=1&y=2#results

In this URL we will breakdown the URL further

  • The protocol is http
  • The domain is www.example.co.in
  • The subdomain is www
  • The top-level domain or TLD id in. The in domain is also referred to as a country-code top-level domain or ccTLD. For example.com, the TLD would be com.
  • The port is 80
  • The path is /example.php
  • The query string is ?x=1&y=2#results. This query string can be further divided into parameter. URLs can have lots parameters. Parameters start with a question mark (?) and are separated with an ampersand (&). First parameter is x with value 1.
  • The hash is #results

Related Articles:

  1. THIS IS THE MOST USEFULL INFORMATION I NEED

Leave a Reply