On this page
Two URL paths can look identical in a browser yet contain different Unicode characters. If a route, proxy, application, or filesystem treats those character sequences differently, one path may resolve while the other returns a 404 or points to a different resource.
This guide explains Unicode URL path normalization, provides a local diagnostic test, and outlines a safe way to investigate existing routes before changing them.
Key Takeaways
- A visible character can have more than one Unicode representation. NFC and NFD turn certain equivalent representations into consistent forms.
- Normalization changes character sequences; percent-encoding represents bytes in a URL. They are different operations.
- URL processing and filesystem behavior vary across the components in a deployment. Test the actual route and storage stack.
- Do not normalize live paths blindly: different sequences may already identify different resources.
Why visually identical paths can differ
Consider a path ending in “café”. The final character can be represented as either:
- A single character,
U+00E9(é). - Two characters,
U+0065(e) followed byU+0301(a combining acute accent).
The two sequences are canonically equivalent in Unicode, but they are not identical strings. NFC generally composes equivalent sequences where possible; NFD decomposes them. Applying the same normalization form to both examples produces matching strings.
This does not mean every pair of similar-looking characters is equivalent. Normalization is not a general solution for visual confusables, case differences, or spelling differences.
Normalization versus percent-encoding
A URL can represent non-ASCII path characters as percent-encoded UTF-8 bytes. For the examples above, the relevant encodings are:
- Composed:
/caf%C3%A9 - Decomposed:
/cafe%CC%81
Percent-encoding does not itself make the character sequences equivalent. A server may decode the percent-encoded bytes and then compare the resulting path without Unicode normalization. Conversely, a component could normalize a path at a later stage. Do not assume that every component in the request chain makes the same choice.
Advertisement
Reproduce the difference locally
The following Python 3 script uses only the standard library. It compares the paths, shows their code points and percent-encoded forms, and checks how a temporary directory on your current filesystem handles two corresponding filenames.
Save it as unicode_paths.py and run python3 unicode_paths.py. The script has not been executed for this article; inspect its printed results on the system you are diagnosing.
from pathlib import Path
from tempfile import TemporaryDirectory
from unicodedata import normalize
from urllib.parse import quote
composed = "/caf\u00e9"
decomposed = "/cafe\u0301"
for label, path in (("composed", composed), ("decomposed", decomposed)):
code_points = " ".join(f"U+{ord(char):04X}" for char in path)
print(label)
print(" repr:", repr(path))
print(" code points:", code_points)
print(" URL path:", quote(path, safe="/", encoding="utf-8"))
print("Strings equal:", composed == decomposed)
print("NFC forms equal:", normalize("NFC", composed) == normalize("NFC", decomposed))
print("NFD forms equal:", normalize("NFD", composed) == normalize("NFD", decomposed))
# Model a route table that compares exact Python strings.
routes = {composed: "existing resource"}
print("Composed route:", routes.get(composed, "not found"))
print("Decomposed route:", routes.get(decomposed, "not found"))
# Check filenames in an isolated temporary directory.
with TemporaryDirectory() as temp_dir:
first = Path(temp_dir) / composed.lstrip("/")
second = Path(temp_dir) / decomposed.lstrip("/")
first.write_text("first file", encoding="utf-8")
print("Second name exists after creating first:", second.exists())
try:
with second.open("x", encoding="utf-8") as file:
file.write("second file")
except FileExistsError:
print("Exclusive creation reported that the second name exists")
else:
print("Exclusive creation of the second name succeeded")
The string comparisons and route-table example demonstrate exact matching independently of a web server. The filesystem portion observes only the temporary directory and runtime used for that run. If it cannot create files there, resolve that local permissions or environment problem before interpreting the test.
A filesystem may consider the names equivalent or allow both, depending on the storage and access environment. A local result does not establish how a production server, mounted volume, object store, or application router behaves.
Trace the path through your deployment
Start with two requests that differ only in the path representation. For a local service listening on port 8000, for example:
curl -i 'http://localhost:8000/caf%C3%A9'
curl -i 'http://localhost:8000/cafe%CC%81'
These commands are probes, not a complete server setup. Use a test route you control, and compare status codes and resource identities. A successful response alone is insufficient: both requests might return a generic fallback page, or they might return different resources.
Trace the requests through the layers that apply to your service:
- Client and edge: Check what path was sent and whether a proxy, CDN, or web server rewrote it.
- Application router: Inspect the path value used for matching, including its code points or UTF-8 bytes. Determine where percent-decoding occurs and whether normalization occurs.
- Storage lookup: Compare the actual lookup keys or filenames. Test the production storage type in a safe environment rather than assuming it behaves like a developer laptop.
- Response: Verify which resource was selected, not just the HTTP status.
When logging diagnostic values, avoid recording sensitive paths or query parameters unnecessarily. A framework-exposed path may already have been decoded or transformed, so distinguish it from any raw request target available at the edge.
The WHATWG URL Standard and the documentation for your deployed filesystem are relevant to this investigation, but they could not be consulted in this run. Verify the behavior and configuration of your actual URL-processing and storage components against their documentation before changing production routing.
Advertisement
Choose a policy without breaking existing URLs
For a new application, choosing a normalization form such as NFC at a clearly defined boundary can make lookup keys more consistent. Apply the same policy when creating and retrieving records, and document it for every service that participates in the lookup.
For an existing application, investigate before rewriting:
- Inventory existing routes and stored names in both their original form and a normalized comparison form.
- Identify collisions: two existing names may normalize to the same key while currently referring to different resources.
- Test representative requests through the full deployment, including links already in use and uploaded filenames.
- Decide how to handle collisions and preserve access before migrating data or introducing redirects.
- Roll out with monitoring and a rollback plan. Check integrations and cached links as well as browser requests.
A redirect to a canonical path can be useful when both representations are intended to identify the same resource. It is not safe to assume that intent for existing paths. Likewise, normalizing only at upload time or only at lookup time can make files unreachable.
Common Mistakes
- Treating percent-encoding as normalization. Decoding
%C3%A9produces a different character sequence from decodinge%CC%81. - Testing only visual appearance. Inspect code points or bytes; fonts can hide the difference.
- Assuming the local filesystem predicts production. Different storage systems and intermediate services can apply different comparison rules.
- Normalizing an entire URL string indiscriminately. Parse URL components and define a policy for the relevant path data. Encoded separators and decoding order can affect routing.
- Merging existing names without checking collisions. Canonically equivalent names may have been stored as separate resources.
Best Practices
Keep URL decoding, Unicode normalization, authorization, routing, and storage lookup consistent and explicit. For filesystem-backed routes, normalization is not a substitute for validating path components, enforcing an authorized storage boundary, and accounting for traversal and symbolic links.
Add regression tests for composed and decomposed forms at the application boundary and, where relevant, against the actual storage backend. Include tests for both intended aliases and names that must remain distinct under your migration policy.
Conclusion
When a Unicode path works on one system but fails on another, compare its underlying characters and trace the request through routing and storage. Normalize consistently only after understanding existing resource identities and testing the effects on your deployment.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.