DevKit
Tester

URL Parser

Break a URL into protocol, host, path, query, and hash components.

Last updated: August 2026

Share:

Was this tool helpful?

Breaking a URL into parts

A URL packs several components into one string: the protocol, host, optional port, path, query string, and fragment. A parser splits them out so you can read or manipulate each piece without fragile string slicing. The structure follows a well-defined grammar, which is why a proper parser beats hand-written splitting on ? and /.

The anatomy

Take https://user@ex.com:8080/path?q=1&sort=asc#top. The scheme is https, the host ex.com, the port 8080, the path /path, the query q=1&sort=asc, and the fragment top. The fragment after # is never sent to the server; it is purely client-side.

Example

https://ex.com:8080/a/b?x=1&y=2#sec
protocol: https:
host:     ex.com
port:     8080
path:     /a/b
query:    x=1&y=2  -> { x: "1", y: "2" }
hash:     #sec

Query strings are trickier than they look

A key can appear more than once, so a=1&a=2 is a list, not a single value, and different frameworks handle that differently. Values are percent-encoded, so a parser should decode them; a raw split leaves %20 in place. For encoding values before you build a URL, use the URL encoder.

FAQ

Why is my fragment missing on the server? By design. Everything after # stays in the browser and is never sent in the request.

What happens with no explicit port? It defaults by scheme: 443 for https, 80 for http. Parsers often leave the port blank to signal the default.

How are duplicate query keys handled? It varies. Some keep the first, some the last, some collect all into an array, so check your framework's rule.