Why Browsers Normalize Dot Segments in URL Paths

Learn how browsers resolve URL dot segments, how encoded dots and relative paths behave, and why server routing can produce different results.

Published
Reading time
5 min read
Why Browsers Normalize Dot Segments in URL Paths
On this page

Browsers often change a URL path before navigating to it: /docs/guide/../api becomes /docs/api. This behavior can make a route appear to receive a different path from the one in a link or address bar. This guide explains URL dot segments, relative resolution, and where browser normalization ends and server routing begins.

Key Takeaways

  • A . path segment refers to the current path level; .. moves up one level.
  • Browsers resolve dot segments when parsing HTTP and HTTPS URLs, including certain percent-encoded forms.
  • Relative URLs are resolved against a base URL. Whether the base ends in / changes the result.
  • Browser normalization is not the same as server-framework routing or filesystem access control.
  • Encoded slashes and repeated decoding can behave differently across servers and intermediaries; test your actual stack.

URL dot segments explained

A path segment is a portion of a URL path between slashes. In hierarchical HTTP and HTTPS URLs, two segments have special meaning during URL resolution:

  • . means stay at the current level.
  • .. means remove the preceding path segment, if there is one to remove.

For example, parsing https://example.com/docs/guide/../api produces https://example.com/docs/api. The browser does not need to ask the server whether /docs/guide exists to do this: it is resolving the URL path, not traversing a filesystem.

Names that merely contain dots are different. A segment such as file.txt, .well-known, or ... is not a dot segment and is not removed by this rule.

Advertisement

Absolute and relative URL examples

The following examples use the JavaScript URL constructor, available in modern browsers. Open a browser console and run them to inspect the serialized URLs:

const base = 'https://example.com/docs/guides/page.html';

console.log(new URL('https://example.com/a/./b/../c').href);
// https://example.com/a/c

console.log(new URL('../img/logo.svg', base).href);
// https://example.com/docs/img/logo.svg

console.log(new URL('/docs/guides/../img/logo.svg', base).href);
// https://example.com/docs/img/logo.svg

console.log(new URL('../../../index.html', base).href);
// https://example.com/index.html

The second and third expressions resolve to the same serialized URL. The final example shows that extra .. segments cannot move above the URL path's root.

These examples have not been executed for this article. Run them in the browsers you support, particularly when debugging behavior involving encoded characters.

The base URL's trailing slash matters

When resolving a relative reference, the last segment of a base path without a trailing slash is treated as the part to replace:

console.log(new URL('child', 'https://example.com/docs/guide').href);
// https://example.com/docs/child

console.log(new URL('child', 'https://example.com/docs/guide/').href);
// https://example.com/docs/guide/child

A leading slash in the reference, as in /child, instead starts the path at the origin's root. Query strings and fragments are separate from the path: two URLs with the same normalized path can still differ in their queries or fragments. A fragment is not sent as part of the HTTP request, but a query can affect the server response.

Percent-encoded dot segments

For HTTP and HTTPS URLs, browser URL parsing recognizes percent-encoded dots in dot segments. Hexadecimal letter case does not matter. These examples show forms that are treated as . or .. segments:

console.log(new URL('https://example.com/a/%2e/b').href);
// https://example.com/a/b

console.log(new URL('https://example.com/a/.%2E/b').href);
// https://example.com/b

console.log(new URL('https://example.com/a/%2e%2e/b').href);
// https://example.com/b

The mixed forms %2e. and .%2e also represent double-dot segments for this purpose. This does not mean every percent-encoded character is decoded before the browser splits the path. In particular, an encoded slash such as %2F is not treated as an ordinary path separator by browser URL parsing:

console.log(new URL('https://example.com/a%2Fb').pathname);
// /a%2Fb

Likewise, %252e%252e is not itself a browser-recognized double-dot segment. A downstream component that decodes repeatedly could interpret it differently. Servers, proxies, and frameworks vary in whether and when they decode encoded characters or reject them, so these browser examples do not predict every server's behavior.

Advertisement

Browser parsing versus server routing

For a normal browser navigation, parsing and resolution happen before the request is made. A server generally receives the browser's normalized request target rather than the literal dot segments originally typed into the address bar. Other HTTP clients may behave differently, and a proxy or server can apply additional normalization before a framework matches a route.

When debugging a mismatch, compare each stage rather than assuming they are identical:

  1. Use new URL(reference, base).href to see how the browser resolves the link. If the link is relative, record the actual base URL too.
  2. Inspect the request URL in the browser's Network panel. Check the query separately from the path.
  3. In an authorized test environment, compare the request target observed at your edge proxy with the path exposed to your application. Log only data appropriate for your privacy and security policies.
  4. Check the documentation and configuration for each proxy, server, and framework involved, especially around encoded slashes and decoding.
  5. Repeat with a controlled test client if you need to investigate requests that a browser normalizes before sending.

Browser normalization is not a security boundary. If a server uses URL paths to select files or authorize resources, it must validate and enforce access using the representation and filesystem behavior relevant to that server. Do not assume the browser removed every dangerous form, or that a proxy and application interpret a path identically.

Common Mistakes

  • Treating every dot as special. Only complete dot segments and the recognized encoded forms have the resolution behavior described above.
  • Forgetting the base URL. ../api can resolve differently depending on the current document URL and its trailing slash.
  • Assuming the address-bar input is the server's input. The browser may normalize it before the request; intermediaries may then make further changes.
  • Assuming %2F and / are interchangeable everywhere. Their handling depends on the component and configuration.
  • Comparing only paths. Queries, origins, and application behavior can distinguish requests even when their normalized paths match.

Best Practices

Use the URL API to resolve links instead of manually concatenating path strings. Test representative links with and without trailing slashes, plus the encoded forms relevant to your application. For routing and access-control decisions, document which component decodes and normalizes each request, and reject ambiguous inputs where your system cannot interpret them consistently.

The WHATWG URL Standard was not independently consulted for this draft because source-retrieval tools were unavailable. Verify the exact parsing rules against the standard and your target browsers before relying on edge-case behavior.

Conclusion

Dot-segment normalization gives browsers a consistent way to resolve hierarchical URL paths. When a route behaves unexpectedly, inspect the browser-resolved URL first, then trace how each server-side component interprets the request.

What would your domain sell for?

A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.