· 5 min read
How to Break Down a URL Into Its Parts
Heshan Fernando
Co-founder & COO
You’ve got a URL like https://user:pass@api.example.com:8443/v2/search?q=red%20shoes&sort=price#results and you need to know exactly what’s in it — which part is the host, which is the query string, and what that %20 actually decodes to. Reading it character by character works if you’re patient, but it’s easy to miscount where the path ends and the query begins, especially once you throw in encoded spaces, ampersands inside values, or a port number tucked between the host and the path.
This comes up constantly for anyone debugging a redirect, writing a router, checking an affiliate link, or verifying that a webhook URL is pointing where it should. You could paste it into a script and call new URL(), but that means opening an editor, writing three lines of throwaway code, and running it — for something that should take five seconds.
What parsing a URL actually involves
A URL isn’t one string — it’s a structured format with fixed slots: scheme (https), optional userinfo, host, optional port, path, optional query string, and optional fragment (the part after #). Each of those slots has its own encoding rules, which is why query values often show up percent-encoded (%20 for a space, %26 for a literal &) while the host generally doesn’t.
Parsing means splitting the string along those boundaries correctly and then decoding the pieces that are encoded, without breaking on edge cases like a @ inside a path, a ? inside a fragment, or a query string with repeated keys (?tag=a&tag=b).
Why people get stuck here
- Query strings with repeated or empty keys.
?filter=&filter=red&filter=bluelooks messy by hand, and it’s easy to lose one of the values when eyeballing it. - Percent-encoding that hides the real content. A tracking URL with
%3F,%2F, and%26baked into a query value is unreadable until it’s decoded — and decoding it wrong (e.g. decoding the whole URL instead of just the query values) can corrupt the structure. - Userinfo and ports that shift everything else.
https://admin:secret@10.0.0.5:3000/dashboardhas five distinct components before the path even starts, and manual parsing often mis-splits the host from the port. - Relative vs. absolute confusion. A URL missing a scheme (
//cdn.example.com/app.js) parses differently than most people expect.
What a good URL parser looks like
Every component labeled separately
Protocol, credentials, host, port, path, query, and hash should each show up as their own labeled field — not just a flattened list of “parts.”
Automatic decoding of encoded values
Percent-encoded characters in the path and query should be decoded for you, so %20 reads as a space and q=red%20shoes reads as red shoes, without you doing the lookup table in your head.
Query parameters broken into key-value pairs
?q=red+shoes&sort=price&sort=name should come back as a readable list, including the fact that sort appears twice — a detail that’s genuinely easy to miss when scanning a long query string.
Common mistakes to avoid
- Assuming a URL without
https://in front is still parseable the same way — a bareexample.com/pathis often treated as a relative path, not a host. - Manually splitting on
&without accounting for&in URLs copied out of HTML source, which introduces phantom parameters. - Decoding the entire URL string at once instead of decoding path and query values individually — this can turn a legitimately encoded
/inside a value into a path separator. - Forgetting that a fragment (
#section) is never sent to the server at all, so debugging server-side behavior based on fragment contents is a dead end. - Missing that ports are optional and default per scheme —
https://implies 443,http://implies 80, and a parser that always shows a port can be misleading if you don’t check whether it was explicit in the original string.
How to do it with URL Parser
Online Tool Store’s URL Parser does the split-and-decode work in your browser, with nothing sent to a server.
- Paste the full URL, including any query string or fragment.
- Read off the protocol, credentials, host, port, path, query, and hash as separate labeled fields.
- Check the decoded query parameters list to see each key and value on its own line, already percent-decoded.
- Copy just the piece you need — the host for a DNS check, the query string for a webhook debug, or the decoded value for a tracking parameter.
Frequently asked questions
Why does my URL show a port I didn’t type?
Some parsers fill in the default port for the scheme (443 for https, 80 for http) even when you didn’t include one explicitly. A good parser should distinguish an explicit port from an implied default rather than presenting both the same way.
Can this handle URLs with special characters in the query string?
Yes — that’s the main reason to use a parser instead of reading it by eye. Percent-encoded characters like %40 (@) or %2B (+) inside a query value get decoded automatically, so you see the actual intended value instead of the encoded form.
Does parsing a URL send it anywhere?
Not with a browser-based parser. The string never leaves your device, which matters if the URL you’re inspecting contains a session token, an API key, or credentials in the userinfo section — none of which you want passed to a third-party server.
Final thought
If you only need to glance at a domain, reading the URL by eye is fine. The moment there’s a query string with more than two parameters, encoded characters, or a port and credentials mixed in, a parser saves you from the kind of off-by-one mistake that turns into a 20-minute debugging detour.