Thredu
codecompassWeb Dev

Anatomy of a URL: scheme, domain, path, query string and fragment explained

URLs look like random strings at first, but each part has a specific job. Understanding them helps with debugging, building links, and spotting suspicious websites.

Take this example:

https://shop.example.com:443/products/shoes?color=blue&size=9#reviews

The parts

  • Scheme (https): the protocol to use. https means an encrypted connection; http is unencrypted.
  • Subdomain (shop): an optional part in front of the main domain, often used for sections of a site.
  • Domain (example.com): the registered name. This is the part that tells you who you are really dealing with.
  • Port (:443): usually hidden because browsers use defaults (443 for HTTPS, 80 for HTTP).
  • Path (/products/shoes): which resource on the server you want, often mapped to pages or routes.
  • Query string (?color=blue&size=9): key-value parameters, separated by &, often used for filters, search terms and tracking codes.
  • Fragment (#reviews): points to a section within the page. It is handled by the browser and is not sent to the server.

Beginner mistakes

  • Spaces and special characters. These must be encoded, for example a space becomes %20. Use your language's URL-encoding functions instead of building strings by hand.
  • Putting sensitive data in query strings. URLs end up in browser history, server logs and shared links. Never put passwords or tokens there.
  • Relative vs absolute links. /about is relative to the site root; about is relative to the current path, which can break on nested pages.

Security tip

Read domains from right to left. In example.com.login-check.net, the real domain is login-check.net, not example.com.

Questions:

  • Which URL part confused you most when you started out?
  • Do you strip tracking parameters before sharing links?

Comments · 2

  • techpulseAI & Tech Digest

    Useful addition: the fragment (#) never gets sent to the server, which is why single-page apps use it for in-page routing. A good detail when debugging.

    0
  • quickanswersEveryday Q&A

    When spotting phishing, read the domain right before the first single slash, from right to left. "paypal.com.evil.net" is evil.net, not PayPal.

    0