The Addressing System of the Web
"What makes a cool URI? A cool URI is one which does not change. What sorts of URI change? URIs don't change: people change them."
— Tim Berners-Lee
CSE 135 — Full Overview
URI is the umbrella term. URL is the most common type — it tells you how to get there.
https://)urn:isbn:978-0-13-468599-1)Scheme (how) • Authority (where) • Path (what) • Query (filters) • Fragment (within)
| Component | Separator | Required? | Example |
|---|---|---|---|
| Scheme | :// (after) | Yes | https |
| Authority | // (before) | Yes (for web URLs) | www.example.com:443 |
| Path | / (segments) | Yes (at least /) | /products/search |
| Query | ? (before), & (pairs) | No | category=books&sort=price |
| Fragment | # (before) | No | results |
The scheme tells the client how to retrieve the resource — what protocol to use.
| Scheme | Purpose |
|---|---|
https | Secure HTTP (encrypted) |
http | Unencrypted HTTP |
wss | Secure WebSocket |
| Scheme | Purpose |
|---|---|
mailto | Email composition |
tel | Phone call |
sms | SMS message |
| Scheme | Purpose | Example |
|---|---|---|
ftp | File Transfer (legacy) | ftp://files.example.com/pub/ |
file | Local filesystem | file:///Users/jane/index.html |
data | Inline data (section 10) | data:text/plain,Hello%20World |
geo | Geographic coordinates | geo:37.7749,-122.4194 |
App-specific schemes: slack://, spotify://, vscode://, zoommtg:// — deep linking into native apps.
http:// for new websites.
Which server to connect to — domain or IP, plus optional port number.
example.com) or IP address (93.184.216.34). DNS translates between them.www., api., blog., mail.| Scheme | Default Port | With Port | Without (same thing) |
|---|---|---|---|
http | 80 | http://example.com:80/page | http://example.com/page |
https | 443 | https://example.com:443/page | https://example.com/page |
ftp | 21 | ftp://files.example.com:21/ | ftp://files.example.com/ |
example.com, your browser first asks DNS for the IP address, then connects. Only specify the port when it's not the default (e.g., localhost:3000).
The hierarchical address of the resource on the server — like a filesystem directory structure.
/About and /about as different resources. Windows (IIS) treats them the same. Always use lowercase./products/ traditionally implies a collection; /products implies a resource. Be consistent.Key-value pairs after ? — search, filtering, sorting, pagination, tracking.
| Use Case | Example |
|---|---|
| Search | ?q=search+terms |
| Filtering | ?category=books&author=Doe |
| Pagination | ?page=2&per_page=25 |
| Sorting | ?sort=date&order=desc |
| Tracking | ?utm_source=google&utm_medium=cpc |
| Multiple values | ?color=red&color=blue |
Starts with # — handled entirely by the browser, never sent to the server.
#introduction, #chapter3 — scrolls to an element with that id#settings, #profile — show a specific tab#/users/42 — hash-based routing (changing the hash doesn't trigger a page reload)Full addresses vs partial addresses resolved against the current document.
| Type | Example | Meaning |
|---|---|---|
| Same directory | page.html | File in the current directory |
| Child directory | images/photo.jpg | File in a subdirectory |
| Parent directory | ../styles/main.css | Go up one level, then into styles/ |
| Root-relative | /images/logo.png | Relative to the site root |
Given base URL https://example.com/blog/posts/article.html:
| Relative URL | Resolved To |
|---|---|
other.html | https://example.com/blog/posts/other.html |
../about.html | https://example.com/blog/about.html |
/styles/main.css | https://example.com/styles/main.css |
//cdn.example.com/lib.js | https://cdn.example.com/lib.js |
The <base> tag changes the base URL for all relative URLs on the page:
Gotcha: <base> affects all relative URLs, including #section fragment links.
/images/logo.png) for site-wide assets — works from any page depth../styles/main.css) for resources that move with the documenthttps://cdn.example.com/lib.js) for external resources//cdn.example.com/...). Just use https://. They were a transitional pattern and break with file://.
URLs can only contain a limited set of ASCII characters — everything else must be encoded as %XX.
A-Z a-z 0-9 - _ . ~: / ? # [ ] @ ! $ & ' ( ) * + , ; =< > { } | \ ^ `, all non-ASCII| Function | Purpose | Use For |
|---|---|---|
encodeURIComponent() | Encode a single value | Query parameter values, path segments |
encodeURI() | Encode a full URL | Complete URLs (preserves structure) |
%20 — standard percent-encoding (used in paths and most contexts)+ — only valid in query strings of application/x-www-form-urlencoded (HTML forms)%20. It's always correct.encodeURIComponent() for values. Never build URLs by string concatenation. Use the URL API (section 15) for building URLs programmatically.
Embed resource content directly in the URL itself — no HTTP request needed.
| MIME Type | Typical Use |
|---|---|
text/plain | Simple text content |
text/html | Inline HTML documents, iframes |
image/svg+xml | Inline vector graphics (icons, logos) |
image/png | Small raster images (base64) |
data:text/html can contain JavaScript. CSP headers can restrict them. Be cautious with user input.
URLs make state shareable and bookmarkable — one of the oldest state mechanisms on the web.
The History API updates the URL without triggering a page reload:
| Aspect | Hash Routing (#/path) | History API (/path) |
|---|---|---|
| URL appearance | example.com/#/users/42 | example.com/users/42 |
| Server config | None needed | Requires catch-all route |
| SEO | Poor (fragments not sent to server) | Good (real URLs, crawlable) |
| Modern usage | Legacy SPAs | Standard for modern frameworks |
URLs are user-controllable input. Any part can be manipulated by an attacker.
| Attack | How It Works | Prevention |
|---|---|---|
| Parameter manipulation | ?user_id=42 → ?user_id=1 | Server-side authorization |
| Open redirect | /login?redirect=https://evil.com | Whitelist domains; relative URLs only |
| Path traversal | /files/../../etc/passwd | Normalize paths; reject .. |
| XSS via URLs | /search?q=<script>alert(1)</script> | HTML-escape; use CSP |
| javascript: scheme | <a href="javascript:..."> | Only allow http:/https: |
| URL phishing | Lookalike domains, homograph attacks | Awareness; browser warnings |
URLs are exposed in: browser history, server logs, Referer header, proxy logs, and bookmarks.
Authorization, Cookie) or request bodies. If a token must be in a URL temporarily (e.g., password reset), make it single-use and short-lived.
Good URLs should last forever. ~25% of links in academic papers are dead within 7 years.
| Bad URL (Why) | Good URL (Why) |
|---|---|
/cgi-bin/display.pl?id=42(exposes technology) | /articles/42(technology-independent) |
/~smith/papers/paper1.html(tied to a person) | /research/machine-learning(topic-based) |
/docs/v2.3.1/api.aspx(version + extension) | /docs/api(stable, versionless) |
Users read, edit, share, and judge URLs. Good URLs are readable, predictable, and hackable.
/products/running-shoes/blog/url-design-tips/about-us/products/shoes/running → /products/shoes/search?q=python → /search?q=javascript| Pattern | Example |
|---|---|
| REST API | /api/users, /api/users/42, /api/users/42/posts |
| Blog | /blog, /blog/2024/url-design |
| Documentation | /docs/getting-started, /docs/api/authentication |
Built-in URL and URLSearchParams classes — always prefer these over string manipulation.
Key takeaways from all 16 sections.
| Concept | Key Points |
|---|---|
| What is a URL | URI is the umbrella; URL tells you how to get there |
| Anatomy | Scheme (how), Authority (where), Path (what), Query (filters), Fragment (within) |
| Scheme | Always use HTTPS. App-specific schemes enable deep linking. |
| Authority | Host + port. DNS resolves domains to IPs. Default ports: HTTP=80, HTTPS=443. |
| Path | Hierarchical, case-sensitive on Linux. Omit file extensions. |
| Query | Key-value pairs for search/filter/sort. Never put secrets in them. |
| Fragment | Never sent to the server. Used for page sections and SPA routing. |
| Relative URLs | Root-relative for assets, absolute for external, document-relative for co-located resources. |
| Encoding | encodeURIComponent() for values. %20 over + when in doubt. |
| Data URIs | Inline resources. Good for small icons; bad for large or cacheable content. |
| State | URL state = shareable/bookmarkable. History API updates without reload. |
| Security | URLs are user input. Validate. Never put secrets in URLs. |
| Cool URIs | Good URLs last forever. 301 redirects when they must change. |
| Interface | Readable, predictable, hackable. The Phone Test. |
| URL API | new URL(), URLSearchParams, URL.canParse(). Always prefer over string manipulation. |