URLs as Information
This guide describes the ways URLs are used to convey information about the resources they lead to, with examples and diagrams developers are familiar with.
Introduction
URL is an acronym that stands for Uniform Resource Locator. To break down that phrase, consider each of its parts:
- Uniform: URLs should all follow a similar pattern
- Resource: What you get when you follow the URL, usually a file (image, video, text, etc.)
- Locator: Tells you the location of the resource you're requesting
In its most basic form, URLs describe the location of any given file on your computer or on the internet. More or less, it's a map with directions on how to get to a file.
Local URLs
While most computer users know about URLs on the web, many don't know that URLs are used on your computer as well. Every file on your computer has its own unique URL, whether it's a text document, a picture, a video, or anything else.
Example (Windows)
Consider the URL below:
C:/Users/Trevor/Downloads/image.jpeg
We can represent this path as a directory tree:
C:/
└── Users/
└── Trevor/
├── Desktop/
├── Documents/
└── Downloads/
└── image.jpeg
This URL is saying:
- Starting in the
C:drive, there is a folder calledUsers - In the
Usersfolder, there is a folder calledTrevor - In the
Trevorfolder, there is a folder calledDownloads - Inside
Downloads, there is a file calledimage.jpeg
Pretty simple, right?
Example (Mac/Linux)
URLs on Mac and Linux start at the "root" folder /. A similar path might look
like this:
/Users/Trevor/Downloads/image.jpg
/
└── Users/
└── Trevor/
├── Desktop/
├── Documents/
└── Downloads/
└── image.jpg
Note: A local URL is sometimes called a "path." The above URL could be described as the "path" to access the image file.
Absolute vs Relative URLs
Absolute URLs
The path /Users/Trevor/Downloads/image.jpg is absolute because it starts
from the root directory. It doesn’t matter where you are in the system—absolute
paths always start from / (root) or a drive (C:/ on Windows).
Relative URLs
Relative paths describe a file location relative to the current working
directory. To indicate that a URL starts from the current directory, use ./.
Current Directory: /Users/Trevor
./Downloads/image.jpg
- From
/Users/Trevor, the relative URL to the image is./Downloads/image.jpg - From
/Users/Trevor/Downloads, the relative URL is just./image.jpg
Traversing Parent Directories
Relative paths can also move into a parent directory using ../. This can
be repeated multiple times to move up the folder structure.
Example
Current directory: /Users/Trevor/Desktop
Desired file: /Users/Trevor/Downloads/image.jpg
Relative path: ./../Downloads/image.jpg
/Users/Trevor/
├── Desktop/ (current directory)
└── Downloads/
└── image.jpg
Steps:
- Starting in
Desktop ../moves up one level →/Users/Trevor- Move into
Downloads/ - File is
image.jpg
Absolute vs Relative (Comparison)
If the file is deeply nested, relative paths can be messy:
- Relative:
./../../../Downloads/image.jpg - Absolute:
/Users/Trevor/Downloads/image.jpg
Most developers prefer absolute paths for clarity when files are far apart.
Web URLs
Web URLs behave similarly to file paths but start from a domain instead of a drive or root directory.
Domain example: https://www.site.com
Everything after .com is essentially the path.
Example (Wikipedia)
URL:
https://en.wikipedia.org/static/images/project-logos/enwiki-2x.png
Directory-like breakdown:
https://en.wikipedia.org/
└── static/
└── images/
└── project-logos/
└── enwiki-2x.png
This URL is saying:
- Start from the domain
https://en.wikipedia.org - Go into the folder
static - Then
images - Then
project-logos - Inside is the file
enwiki-2x.png
Copying this URL into your browser will download or render the image.
Caveat
The internet is a diverse ecosystem of apps written in different languages. At a fundamental level, everything above is true. However, some websites implement non-standard routing (e.g., URLs may represent database lookups, not file locations). That's a separate discussion.
