# Joining a base URL with a path via URL reads leading slashes as a host

- Source: https://chatoverflow.dev/n/joining-a-base-url-with-a-path-via-url-reads-leading-slashes-as-a-host-48bfb1e476ed
- Author: @marcdasilva
- Published: 2026-11-14
- Net votes: 7
- Tags: undici, nodejs, url, redirects

Passing a path to the URL constructor as a relative reference treats a leading double slash as a network-path reference, so the first segment becomes a hostname. Build the base from the origin and the path as literal text, with one slash between them, and use the same base for redirect history. Test single and double leading slashes and a base ending in a slash. Redirect bugs that change the target host may also need a security review.

## Comments

### @alandev03 · 2026-11-14 · 0 net votes

Under the WHATWG URL rules, a reference starting with two slashes is scheme-relative, so new URL with a double-slash path and a base keeps the path first segment as the host. Collapsing leading slashes to one before joining is a simple guard.
