URLs
URLs
There are several types of URLs based on their structure and the kind of resource they point
to. Below are the main types of URLs:
1. Absolute URL
An absolute URL provides the complete path to a resource, including the protocol, domain
name, and full location of the resource on the server. It gives the complete address of a
webpage or file.
Example:
arduino
Copy code
https://www.example.com/index.html
Protocol: https
Domain Name: www.example.com
File Path: /index.html
2. Relative URL
A relative URL refers to a resource in relation to the current page or location. It doesn’t
include the protocol (http:// or https://) or domain, and it is used when the resource is
within the same domain or website.
Example:
bash
Copy code
/images/logo.png
This points to an image file located in the /images directory on the same website.
Copy code
about-us.html
This links to the about-us.html page, assuming the link is within the same directory
as the current page.
3. Root-relative URL
A root-relative URL starts with a forward slash (/) and points to a resource starting from the
root directory of the website, but it doesn’t include the domain name.
Example:
bash
Copy code
/about/contact.html
This points to the contact.html file in the /about directory, starting from the root of
the website.
4. Protocol-relative URL
A protocol-relative URL omits the protocol (e.g., http:// or https://) and relies on the
protocol used by the page currently being viewed. It automatically adjusts to the protocol of
the page (secure or non-secure).
Example:
arduino
Copy code
//www.example.com/images/banner.jpg
This URL will use the same protocol (either http or https) as the current page.
A URN is a type of URL that identifies a resource by name within a given namespace,
without giving its location. URNs are primarily used to identify resources in persistent,
location-independent ways.
Example:
css
Copy code
urn:isbn:0451450523
This URN points to a specific book identified by its ISBN number, but it doesn’t
provide the location of the book.
6. Data URL
A data URL embeds the data of the resource directly into the URL itself, rather than linking
to an external file. This is used for small files, such as images or text.
Example:
bash
Copy code
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA...
7. File URL
A file URL refers to a local file on a computer or network. It typically starts with file://,
indicating that the resource is stored on the file system rather than a remote server.
Example:
perl
Copy code
file:///C:/Users/John/Documents/example.txt
8. FTP URL
An FTP URL is used to access files over the FTP (File Transfer Protocol). It allows the
transfer of files from one machine to another.
Example:
arduino
Copy code
ftp://ftp.example.com/pub/file.txt
This URL points to a file file.txt in the /pub directory on an FTP server.
9. mailto URL
A mailto URL is used to create a link that opens an email client with the recipient's email
address pre-filled.
Example:
graphql
Copy code
mailto:[email protected]
Clicking this URL will open the default email client with the recipient’s email address
filled in.
A tel URL is used to link to a phone number, which, when clicked, will prompt the device to
dial the number (useful in mobile environments).
Example:
makefile
Copy code
tel:+1234567890
Each type of URL serves a unique function depending on the resource you're trying to access
or the action you're trying to perform.
A URL (Uniform Resource Locator) consists of several components that together specify
the address of a resource on the web. Here’s a breakdown of the structure of a URL:
1. Scheme (Protocol)
Definition: This part specifies the protocol or method used to access the resource.
Example: http, https, ftp, mailto, etc.
Purpose: It tells the browser or application which protocol to use when accessing the
resource.
Example: https:// indicates that the HTTP protocol is used with encryption (SSL/TLS).
2. Domain (Host)
Definition: The domain name identifies the server where the resource is hosted.
Example: www.example.com
Purpose: It’s the address of the server or machine that is hosting the resource. This
can be a fully qualified domain name (FQDN) or an IP address.
3. Port
Definition: The port is an optional component that specifies the port number on the
server to which the request is sent. If omitted, the