Designing Effective URLs: Understanding URI, URL, and URN
Effective URL design, covering the distinctions and relationships among URI, URL, and URN, best practices for stability, readability, and longevity, as well as technical considerations such as Data URIs, hash fragments, redirects, and real‑world examples like Flickr, provides essential guidance for web architects and developers.
URL design is a critical yet often overlooked aspect of system architecture; a well‑designed URL can improve usability, maintainability, and longevity of web resources.
URI, URL, and URN
URI (Uniform Resource Identifier) is the top‑level concept that identifies a resource. URL (Uniform Resource Locator) and URN (Uniform Resource Name) are sub‑categories of URI. A URL locates a resource, while a URN provides a persistent name independent of location.
URI: generic identifier
URL: location‑based identifier
URN: name‑based identifier
URNs act like personal names, URLs like addresses. For example, an ISBN is a URN; the same book’s file path on a server is a URL.
URL Structure
A typical URL consists of three parts: protocol (scheme), host (optionally with port), and resource path.
Protocol (e.g., http , https )
Host/IP address (may include port)
Path to the resource (directories, file name)
The first two parts are mandatory; the path can be omitted in some cases.
URN Structure
URN follows the syntax URN:NID:NSS , where NID is a namespace identifier registered with IANA and NSS is a namespace‑specific string.
Example for ISBN: URN:ISSN:1234-5678 .
Data URI (an immature technique)
Defined in RFC 2397, Data URI embeds small files directly in a document.
Syntax:
data:[<MIME-type>][;base64],<data>Advantages: reduces HTTP requests, can lower bandwidth for tiny assets, works well on HTTPS, and enables a single‑file page.
Disadvantages: cannot be reused, not cacheable, increases size due to base64 encoding, and may pose security concerns.
Principles of a Good URL
Stable for years (avoid changing URLs)
Easy to remember and type
Short and readable
Reflects site structure
Predictable and uniform
Never expose implementation details (e.g., avoid cgi-bin in paths)
Common reasons URLs change include site redesign, document expiration, moving files, switching from scripts to binaries, or misunderstanding that URLs need to be mutable.
Design Recommendations
Avoid embedding mutable information such as author names, titles, status flags, access levels, file extensions, or program mechanisms.
Prefer numeric or date‑based identifiers that remain constant.
Use hyphens instead of underscores, keep words short, and limit total length to about 80 bytes.
Maintain a stable root section; decide it before coding.
Leverage namespaces (e.g., github.com/pallets/flask ) to organize content.
Utilize query strings for sorting and filtering, but ensure the page renders correctly without them.
Handle non‑ASCII characters carefully; prefer ASCII for usability and SEO.
Hash Fragments
The part after “#” identifies a location within the page; it is never sent to the server. Changing the fragment updates browser history without reloading the page, useful for Ajax navigation.
Redirects and HTTP Status Codes
When a URL changes, use standard redirects:
301 Moved Permanently
302 Found
307 Temporary Redirect
For removed resources, return HTTP 410.
Flickr API URL Examples
Flickr defines three image URL patterns:
http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}.jpg http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{secret}_[mstzb].jpg http://farm{farm-id}.static.flickr.com/{server-id}/{id}_{o-secret}_o.(jpg|gif|png)Size suffixes (s, t, m, -, z, b, o) indicate dimensions. Flickr also provides short URLs using Base58 encoding, e.g., http://flic.kr/p/{base58-photo-id} .
Conclusion
URLs are the primary interface between users and web services; they should be treated with the same care as a brand logo or a business phone number. Stable, readable, and well‑structured URLs improve user trust, SEO, and long‑term maintainability.
IT Architects Alliance
Discussion and exchange on system, internet, large‑scale distributed, high‑availability, and high‑performance architectures, as well as big data, machine learning, AI, and architecture adjustments with internet technologies. Includes real‑world large‑scale architecture case studies. Open to architects who have ideas and enjoy sharing.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.