URL is an acronym standing for Uniform Resource Locator. A URL is a string of characters identifying the location of a resource on a computer network.
Generally, URLs are used to locate the address of a web page, an image, a file, or any digital resource on the internet that you usually type in the address bar of your browser in order to visit or download it.
For example, the following is the URL of AppDevTools that you use to visit the site.
https://www.appdevtools.com
URI is an acronym standing for Uniform Resource Identifier. A URI is a means to identify a resource by either name, location, or even both.
URIs are the superset of URLs and URNs, so URLs and URNs themselves are also URIs. However, some URIs may not be any of URLs and URNs. To put it simply, if there is a protocol, such as http
or https
, you can tell that it's a URL. And if the protocol is urn
, it's a URN.
The following is an example of a URI of a zip file on an FTP server.
ftp://example.com/file.zip
URN is an acronym standing for Uniform Resource Name. A URN is used to identify a resource by name. You can easily tell which URIs are URNs because URNs always begin with the urn
scheme.
The following is an example of a URN that represents a UUID.
urn:uuid:6b998725-edf7-4b91-98bf-ce7f4bf6e873
URLs consist of several parts including mandatory and optional ones. Therefore, the structure of each URL can be vary depending on the use of it. Here are the most used components of a URL that can be found in general when parsed.
The following is the syntax of a URL.
scheme://[userinfo@]host[:port]path[?query][#fragment]
Protocol - Protocol or scheme indicates which protocol to use to access the resource on a computer network. The most used protocols commonly found on the internet include http
, https
, ftp
, sftp
, mailto
, and file
. For example, https://www.example.com
.
Userinfo - Userinfo is an optional part consisting of a username and an optional password followed by an at symbol @
right before the hostname. The username and password are split by a colon :
. For example, username:password
.
Hostname - Hostname is an essential part that is always present in every URL as it indicates the targeted server. A hostname consists of three particular parts; i.e. subdomain, domain name, and TLD (Top Level Domain) respectively while the subdomain part is optional. A hostname can be simply just an IP address as well if no domain name assigned to it.
Port - Port number defines which port to access resources on the targeted server. The http
and https
protocols use port 80 and 443 respectively by default, and these ports are omitted in a URL. The port part can be specified by adding a semicolon :
followed by a port number to the hostname. For instance, https://www.example.com:1234
.
Path - Path indicates the location of a resource on the server. It can be either a physical or an abstract location. The separator for a URL path hierarchy is forward slashes /
. If a URL is for a blog post, the path component that defines the title of the post can also be called a slug. For example, https://www.example.com/post/my-first-post
.
Query String - Query string is an optional part in a URL usually found in dynamic pages right after the question mark separator ?
in a URL. A query string consists of parameters in the key-value format. The separator for each parameter in a query string is the ampersand &
. For example, https://www.example.com/?name=john&age=30
.
Fragment - Fragment is an optional part also known as a hash or an HTML anchor located at the last part of a URL. Fragment is indicated by a hash symbol #
followed by a string which refers to a certain section within a page, such as a heading of an article. For example, https://www.example.com/about.html#introduction
.
The following is an example of a URL containing a query string.
https://www.example.com/post/?id=1
A query string is used to pass parameters to a web or an API server via a URL. It can be used to access a dynamic page on a website, such as a blog post or simply fetch information from a database and return a JSON string as a result.
As you can tell from seeing the path and query string parameter in the example URL above, such a URL is typically used for retrieving a blog post where post
is the path in the URL, id
is the key representing to the post ID, and 1
is the value of the id
key specifying which post ID to retrieve from the database.
You can pass multiple parameters in a query string using the ampersand &
as a separator as in the following URL.
https://www.example.com/product/?category=phone&maxprice=500
A web server will parse such a URL into individual parameters and retrieve the corresponding information from the database based on the provided parameters. In this case, all the products listed in the phone
category that cost lower than $500
will be displayed.
A URL shortener is an online service to keep URLs short by pointing a shortened URL to the destination one which is usually longer and difficult to remember.
Shortened URLs are most useful on a platform where the length of a message is limited to a certain number of characters, such as Twitter or SMS. Therefore, they can help save some characters in a message while still pointing to the full URL.
However, shortened URLs can be dangerous as well because the destination URLs are hidden unless clicked, so you completely have no idea where they will redirect you to. For example, they can lead you to a phishing or malicious site. You can test a shortened URL to see if it's safe using an online tool before opening it anyway.
For example, the URL below is Twitter's URL shortener service used within Twitter for outgoing links.
https://t.co