Contents

Web & Networking › HTTP

URL

The address of a resource: scheme, host, path, query and fragment.

Also known as: Uniform Resource Locator, web address, link, URI

A URL is the address of a resource on the internet. Every part has a job:

https://user@shop.example.com:8443/products/42?color=red&page=2#reviews
└─┬─┘   └─┬─┘ └──────┬───────┘└─┬─┘└────┬────┘└──────┬───────┘└──┬───┘
scheme  user   host (domain)  port  path       query         fragment
PartMeaning
SchemeThe protocol: https, http, ftp…
HostThe server’s domain name or IP address
PortWhich service on that host (omitted when it’s the default: 80 for HTTP, 443 for HTTPS)
PathWhich resource: /products/42
QueryExtra parameters after ?, as key=value pairs joined by &
FragmentA spot within the page, after #. The browser doesn’t send it to the server

Practical points

  • Special characters must be encoded (a b → a%20b). See URL encoding.
  • Absolute vs relative. https://example.com/a is complete; /a is relative to the current host; ../a relative to the current path.
  • Don’t build or parse URLs with string tricks. Use the language’s URL tools:
const url = new URL("https://example.com/search");
url.searchParams.set("q", "red kettle");
url.toString();      // "https://example.com/search?q=red+kettle"
from urllib.parse import urlparse, urlencode
urlparse("https://example.com/a?x=1").netloc      # 'example.com'
  • Don’t put secrets in URLs. They’re logged, saved in history and sent in referrer headers.
  • Two URLs with different origins are treated separately by the browser’s security rules.

“URI” is the broader term (it includes names without a location); in everyday use, people say URL and mean the same thing.