Code

Resolve a relative URL and preserve repeated parameters

·

Compare two base URLs that differ by one slash. Then edit a repeated query parameter and see exactly how a literal plus sign appears in the finished URL.

URL parser

Base URL (optional)

The final slash in the base URL changes the result. A base ending in /docs/ names a directory. A base ending in /docs names a file-like path whose last segment the browser replaces. Try the same relative input with both bases below. With base https://example.org/catalog/items/ and relative input ../sale?size=M#stock, the result has path /catalog/sale, query size=M and fragment stock. Change the base to /catalog/items without its final slash and the path resolves to /sale.

Base URL (optional)
Base URL (optional)URL or pathResult
https://example.org/docs/p?tag=red&tag=blue#tophttps://example.org/docs/p?tag=red&tag=blue#top
https://example.org/docsp?tag=red&tag=blue#tophttps://example.org/p?tag=red&tag=blue#top

WHATWG URL Standard · URL

Query string

Change only the second tag value to C++. In the output, each literal plus becomes %2B. The first tag and the fragment stay intact. If the result surprises you, inspect the base and path fields before editing any query values. Parsing a URL identifies these components locally. It provides no evidence that the destination exists.

Query string
URL or pathResult
https://example.org/docs/p?tag=red&tag=blue#tophttps://example.org/docs/p?tag=red&tag=C%2B%2B#top

WHATWG URL Standard · URLSearchParams

Common questions

What happens to repeated keys?

Both rows are preserved in their original order.

Does parsing visit the address?

The browser reads the address as text on this device.

Sources and further reading

Put it into practice.

Related guides