Lesson 3
Relative URLs and Normalization
Resolve relative paths, preserve intent, and avoid accidental canonical changes.
Not every URL you see is absolute. HTML, routers, redirects, and config files often use relative URLs.
/account/settings
../images/logo.png
?page=2
Relative URLs need a base URL before they can be resolved.
Base matters
Given this base:
https://example.com/docs/guides/url/
../api/ resolves to:
https://example.com/docs/guides/api/
If the base changes to /docs/guides/url, without a trailing slash, resolution can change because the last segment may be treated as a file.
Normalization
Normalization makes equivalent-looking URLs consistent. Examples include:
- Removing default ports
- Resolving
.and..path segments - Lowercasing host names
- Sorting query parameters for a canonical form
Normalization is useful, but it can be dangerous when byte-for-byte identity matters.
Preserve intent
Avoid normalizing signed URLs, cache keys, OAuth redirects, or third-party callback links unless you know the exact canonicalization rules. A harmless-looking rewrite can invalidate a signature or change which endpoint receives a request.
Parsing helps because it lets you see what will change before you rebuild the URL.