A URL Life Cycle:  What is URL And URL Structure

What is URL

URL stands for Uniform Resource Locator or simpler web address that locates a server “Website” or network.

URL Structure

A full structure for a URL is:

From Wikipedia:

URI = scheme:[//authority]path[?query][#fragment]

scheme://[www.]host-name:port[path][?query][#fragment]

Now Let’s understand each part of the url

URL Scheme

A url scheme is the first part of the URL indicates which protocol the browser must use, also called protocol.

Most popular protocol is the http protocol and its secure one the https protocol, this protocol is usually for websites.

Here is the list of most popular protocols:

  • http
  • https
  • file
  • ws

www

www stands for World Wide Web and it can be optionally written or can be removed.

if removed, you’ll have to remove the . with it

Host name

The host name usually is a website name i.e google.com which points to some server IP or a direct server IP that hosts the software that will receive the request.

Port

The port that is used in the server, if not set, the default is 80

Most of the time the port is not present in the url

Path

After we set the host-name and the port optionally, we can tell the server which path we want to execute in the server.

For example: facebook.com/home, here the /home is the path that will receive the request.

Query String

It is an extra information that is send to the server and it’s optionally as well to be set in the url or not based on the server software requirements.

Query String Structure

If the url contains a query string, it must first start with ? then we write key/value pairs like this:

sitenamecom?welcome=home&name=hasan

Here our query string starts after the ? sign, which consist of:

  • welcome=home
  • name=hasan

We can add as many segments parameters as we need by separating between the by & between each parameter.

#fragment

From MDN:

is an anchor to another part of the resource itself. An anchor represents a sort of “bookmark” inside the resource, giving the browser the directions to show the content located at that “bookmarked” spot. On an HTML document, for example, the browser will scroll to the point where the anchor is defined; on a video or audio document, the browser will try to go to the time the anchor represents. It is worth noting that the part after the #, also known as the fragment identifier, is never sent to the server with the request.

It means that we can set some informations to the browser to tell him we need to go/scroll down to the location of that path if exists in the document/web page.

http series1 - A URL Life Cycle: Introduction2 - A URL Life Cycle: What is URL And URL Structure
Programming Concepts#Programming Concepts