What URLs Are Made Of
A URL is a compact instruction for retrieving or locating a resource: which protocol to speak, which server to contact, which path to request, and which parameters to include. Parsers treat certain characters as syntax; data that contains those characters must be encoded or the URL breaks. Understanding each segment helps you debug routing, cache keys, analytics, and open redirects before they become incidents.
7 min read · Updated 2026-10-04

URI, URL, and URN
URI (Uniform Resource Identifier) is the umbrella term. A URL (Uniform Resource Locator) describes how to access a resource—https://example.com/page is a URL. A URN names a resource without location (urn:isbn:978-…). In daily web development, “URL” and “URI” are often used interchangeably for http(s) addresses, but specs distinguish name vs locator. APIs and logs should store canonical URLs with consistent encoding.
Annotated example
https://www.example.com:443/products/item?id=42&color=blue%20green#reviews
Full URL: https://www.example.com:443/products/item?id=42&color=blue%20green#reviews
01 · Scheme
https://
Protocol plus authority delimiter; https implies TLS and default port 443 when omitted.
02 · Subdomain
www.
Host labels left of the registrable domain; still part of the authority sent in the Host header.
03 · Host
example.com
DNS name or IP the client resolves before opening a connection.
04 · Port
:443
Optional; explicit here for teaching—browsers often hide default https port in the address bar.
05 · Path
/products/item
Hierarchical resource path on the server; appears on the HTTP request line (with query).
06 · Query
?id=42&color=blue%20green
Key-value parameters after ?; spaces encoded as %20 (or + in some form bodies—not always interchangeable).
07 · Fragment
#reviews
Client-side anchor only; not sent to the origin on a typical document fetch.
Concatenating the colored segments reconstructs the full URL. Userinfo (user:pass@) is omitted here—modern browsers de-emphasize it in navigation URLs.
What each segment does in HTTP
| Component | Sent to origin? | Typical pitfall |
|---|---|---|
| Scheme | Indirectly (TLS vs cleartext) | Mixed http assets on https pages |
| Authority (host + port) | Host header (+ port if non-default) | Wrong base URL in SPAs and email links |
| Path + query | Request line | Double ? when a nested URL is not encodeURIComponent-encoded |
| Fragment | No | Expecting #section to reach server-side routing |
Parse full URL
Split scheme, authority, path, query, fragment
HTTP request line
Method + path + query + HTTP version
Host header
Authority host (and port if non-default)
Fragment dropped
#syntax never leaves the browser for the network fetch
Render scroll
After response, jump to id=syntax if present in HTML
Fragments enable in-page anchors without server round trips.
Scheme and default ports
Common schemes
| Scheme | Default port | Typical use |
|---|---|---|
| http | 80 | Cleartext HTTP (legacy, redirects to https on modern sites) |
| https | 443 | HTTP over TLS—default for web apps |
| ws / wss | 80 / 443 | WebSockets; wss is TLS-wrapped |
| mailto | — | Opens mail user agent with address parameters |
| file | — | Local file access; special sandbox rules in browsers |
Omitting the port means “use the default for this scheme.” Explicit :8080 overrides when dev servers listen off-standard.
Path, query, and parsing traps
Path segments are delimited by /. Trailing slashes can matter to caches and static hosts—pick one canonical form. Query strings start at ? and use & between pairs; keys and values are separated by =. Empty ?key= sends key with empty value; bare ?key may be treated differently by frameworks. Repeated keys (?tag=a&tag=b) are valid; server code must decide whether to take first, last, or collect all.
Relative URLs resolve against a base (RFC 3986). A link href="guides/foo" on https://example.com/docs/ resolves to https://example.com/docs/guides/foo—bugs appear when bases are wrong in emails or SPAs.
Percent-encoding (URL encoding)
Reserved characters—space, &, =, ?, #, +, /, and others—have syntactic roles. When they appear inside data (search terms, file names), encode them as % followed by two hex digits. Space is often encoded as %20; + in query strings historically meant space in application/x-www-form-urlencoded bodies—do not assume + and %20 are interchangeable in every layer.
const q = "rock & roll";
encodeURIComponent(q); // "rock%20%26%20roll"
// Use encodeURIComponent for query VALUES;
// encodeURI for full URLs without breaking structure.Internationalized domain names and paths
Unicode hostnames appear as punycode (xn--…) in DNS. Paths may contain UTF-8 percent-encoded Unicode when servers and frameworks allow IRIs. Normalization and homograph attacks (cyrillic “a” vs latin “a”) are security concerns—browsers apply same-origin rules on punycode forms.
Origin and same-site rules
The origin combines scheme, host, and port. Cookies, CORS, and fetch policies key off origin—not merely path prefix. A page at https://app.example.com/settings and an API at https://api.example.com are different origins even on the same registrable domain; subdomain takeovers break assumptions if DNS is neglected.
Security considerations
URLs are both navigation and attack surface. Because they appear in address bars, emails, analytics, and server logs, small parsing differences between your framework, a CDN, and a mobile WebView become authorization bugs. Treat every redirect target, callback URL, and webhook endpoint as untrusted input until you have parsed it with a spec-aware API and compared origin, path, and encoded form to an allowlist.
- Open redirects: validate next= parameters against an allowlist of paths or hosts.
- JavaScript URLs: javascript:… in href can execute script; block in user-generated links.
- Mixed content: https pages loading http subresources weaken TLS guarantees.
- Sensitive data in query strings: URLs land in logs, Referer headers, and browser history—prefer POST bodies or headers for tokens.
- Overlong encoding: %252F double-encoding bypasses naive filters—normalize before authorization checks.
- Userinfo phishing: https://evil.com@trusted.com/ may look like trusted.com in UI—modern browsers de-emphasize userinfo.
- Trailing-dot hostnames: example.com. can resolve differently than example.com in some resolvers—normalize before allowlists.
- Backslash vs slash: https://example.com\@evil.com/ tricks parsers that treat \ as / before validation.
- Scheme smuggling: javascript: or data: URLs in href if your sanitizer only checks for http—block non-navigable schemes in user content.
Common mistakes in app code
- Building query strings with string templates instead of URLSearchParams—ampersands in values split parameters silently.
- Using decodeURIComponent on the full href before checking the host—can hide homoglyphs or double-encoded traversal.
- Caching on the full URL string including tracking query order—cache misses and log PII when ids shuffle.
- Assuming Referer omits paths: strict-origin-when-cross-origin still leaks origin; secrets belong in headers or POST bodies.
SSRF and internal hosts
Server-side code that fetches a user-supplied URL (preview cards, importers, webhooks) can be tricked into calling http://127.0.0.1, metadata endpoints, or private RFC 1918 addresses. Block link-local and loopback hosts after parsing; do not rely on string contains checks for localhost. Same-origin policy protects browsers; servers have no such default.
Safer pattern
- 1
Parse with URL API
new URL(input, base) in modern JS
- 2
Allowlist host/path
Compare origin after normalization
- 3
Encode outbound data
encodeURIComponent on values only
- 4
Log redacted URLs
Strip tokens and session ids in analytics
Risky pattern
- 1
String concat
Building URLs with manual ? and &
- 2
Blacklist filters
Blocking literal strings only
- 3
Decode twice loosely
Accepting overlong encodings
- 4
Secrets in query
API keys visible in Referer leaks
Relative resolution in apps
Single-page applications and email templates often ship relative links. RFC 3986 resolution merges a relative reference against a base URL: ../api/v1/users from https://example.com/app/dashboard/ becomes https://example.com/app/api/v1/users when segments are normalized. Wrong base tags in HTML or incorrect router basename settings produce 404s that look like server bugs but are client-side URL algebra mistakes.
const base = "https://example.com/app/page";
const rel = "../api/items?q=1";
console.log(new URL(rel, base).href);
// "https://example.com/app/api/items?q=1"Tools and specs align
SmartKitio’s url-encoder and url-decoder run in the browser so you can percent-encode search terms, nested next= URLs, and non-ASCII path segments without guessing which characters are reserved. When a malformed link returns 404 or 400, http-status-lookup explains what the code means while you split the URL with new URL()—scheme, host, path, and searchParams should be inspected separately, not as one opaque string.
Further reading
- WHATWG URL Standard
- RFC 3986 — Uniform Resource Identifier (URI): Generic Syntax
- MDN — URL
- MDN — encodeURIComponent()
- RFC 9110 — HTTP semantics (origin, routing context) — How requests target resources identified by URL
Related articles

Technology
What Happens When You Enter a URL?
A step-by-step path from keypress to first paint, including DNS, TLS, redirects, and caching.
8 min read · 2026-10-04
Read the article
Programming
Encoding vs Encryption: What's the Difference?
Encoding, encryption, hashing, and compression solve different problems. Confusing them—especially Base64 with secrecy—creates real security failures.
6 min read · 2026-10-04
Read the article
Programming
What Is an API and How Does It Work?
APIs are contracts between programs. HTTP JSON APIs are the visible face—methods, headers, bodies, status codes, auth, and versioning explained.
8 min read · 2026-10-04
Read the article
Web
Client-Side vs Server-Side Processing
Where computation runs shapes privacy, latency, cost, and trust. A practical map of browser work versus server work—and what hybrid apps actually do.
5 min read · 2026-10-04
Read the article
