The double slash that broke navigation
A footer link sent users to //about instead of /about: site_url ended with a slash, the path started with one, and string concatenation produced a double slash that nginx treated as a different path. Six fixes: urljoin semantics, root-relative vs path-relative, a single normalize function, nginx merge_slashes, parameterized tests, and canonical plus 301.
📜 Table of Contents
📖 Keep reading
The double slash that broke navigation
A user reported the footer links were broken. Clicking About landed on https://example.com//about, which returned 404.
One extra character, half a day lost. The config had site_url = "https://example.com/" and the page path was /about. Concatenation gave //about. The browser did not complain; nginx treated it as a different path.

1. Why double slashes 404
Consecutive slashes mean "empty directory segment". Servers do not guess whether it is a typo:
- nginx merges by default (
merge_slashes on), but the merge happens at one layer only; a proxy, CDN, or app middleware downstream can see the raw URI - application routers match exactly, so
//aboutmisses the/aboutroute - for search engines,
//aboutand/aboutare two URLs with the same content
2. Method 1: urljoin, with its two traps
urljoin("https://e.com/blog/", "about") # https://e.com/blog/about
urljoin("https://e.com/blog/", "/about") # https://e.com/about leading slash wins
urljoin("https://e.com/blog", "about") # https://e.com/about blog treated as a file
So: base must end with a slash; child paths should not start with one unless you mean the site root. In JS, new URL(path, base) follows the same rules.
3. Method 2: know root-relative from path-relative
| Form | Meaning | Against https://e.com/shop/ |
|---|---|---|
about |
relative | https://e.com/shop/about |
/about |
root-relative | https://e.com/about |
//about |
protocol-relative, host becomes about |
https://about |
That last row is the dangerous one: //about is not a path, it is a hostname.
Rule: store path segments bare, without leading or trailing slashes, and let one function add separators.
4. Method 3: one normalize function
def join_url(base: str, path: str) -> str:
if not path:
return base
if path.startswith(("http://", "https://")):
return path
return f"{base.rstrip('/')}/{path.lstrip('/')}"
Never use os.path.join for URLs: it uses backslashes on Windows and discards earlier arguments when a later one is absolute.
5. Method 4: server-side backstop
server {
merge_slashes on;
if ($request_uri ~ "^([^?]*?)//+") {
return 301 $scheme://$host$1$is_args$args;
}
}
Keep merging off only where // is meaningful, such as object-storage keys.
6. Method 5: pin it with tests
@pytest.mark.parametrize("base,path,expected", [
("https://e.com", "about", "https://e.com/about"),
("https://e.com/", "/about", "https://e.com/about"),
("https://e.com/shop/", "about", "https://e.com/shop/about"),
("https://e.com/", "", "https://e.com/"),
])
def test_join_url(base, path, expected):
assert join_url(base, path) == expected
Add a scan for href="...//..." in rendered HTML during build.
7. Method 6: canonical and sitemap
If crawlers already saw the doubled URLs, add <link rel="canonical">, keep sitemaps clean, and rely on 301s rather than 404s.
Cost and effect
| Measure | Fixes | Effort |
|---|---|---|
| bare segments + join_url | new occurrences | ~1 hour |
| parameterized tests | regressions | 20 lines |
| nginx 301 | old inbound links | 3 lines |
| canonical + sitemap | indexed duplicates | one config |
FAQ
urljoin or posixpath.join? urljoin. posixpath.join("/a/", "/b") returns /b.
Will fixing links hurt existing rankings? 301s pass signals; hard 404s do not.
Merging is on, still 404? The merge happened upstream; trace the raw URI with curl -v at each hop.
Front-end routers? Same issue, and more common: base + "/" + path produces // the moment base ends with a slash.
Defaults for merge_slashes: see ngx_http_core_module in the official nginx docs.
Related
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.