Fundamentals 26 min read

Designing Robust URLs: Best Practices and Common Pitfalls

This article explains the concepts of URI, URL, and URN, outlines their hierarchical relationship, details URL structure and design principles, discusses Data URIs, hash fragments, and provides real‑world examples such as Flickr API URL patterns to help developers create stable, user‑friendly web addresses.

21CTO
21CTO
21CTO
Designing Robust URLs: Best Practices and Common Pitfalls

URL design is a crucial yet often overlooked part of system architecture; a well‑designed URL can greatly benefit the whole system.

URI, URL, and URN

URI (Uniform Resource Identifier), URL (Uniform Resource Locator), and URN (Uniform Resource Name) are standard ways to identify, locate, and name resources on the Internet. Tim Berners‑Lee introduced these standards in 1989 to address the need for unique identification of both physical and abstract resources.

URI: Uniform Resource Identifier

URL: Uniform Resource Locator

URN: Uniform Resource Name

URI sits at the top of the hierarchy, while URL and URN are sub‑categories of URI.

URL

A URL is a string used to describe an information resource on the Internet, primarily used by web clients and servers. Its format consists of three parts: protocol (service), host IP (sometimes with port), and the specific resource path.

First part and second part are separated by "://", second and third by "/". The third part may be omitted.

The main drawback is that when the resource location changes, the URL must be updated, prompting research into more stable representations.

URN

A URN is a standard‑format URI that identifies a resource without specifying its location. For example, an ISBN is a typical URN: urn:isbn:0-486-27557-4. URNs provide persistent identification, while URLs provide locational information.

Key differences:

URN offers persistent identification.

URL is a path that may change over time and is not guaranteed to be unique or permanent.

URN Structure

URN follows the URI syntax and consists of three parts: URN:NID:NSS, where NID is a namespace identifier registered with IANA and NSS is a namespace‑specific string.

ISSN and URN

ISSN was the first identifier to adopt the URN scheme. Example syntax: urn:issn:1234-5678. It is recommended to record the URN in the metadata of web resources.

URI

A URI is a simple string that uniquely identifies a resource, typically composed of a naming mechanism, host name, and resource name (path). URI is the superset; URL is a subset of URI.

Data URI

Data URI, defined by RFC 2397, embeds small files directly into a document using the syntax data:[<MIME-type>][;base64],<data>. It reduces HTTP requests and can lower bandwidth for small resources, but has drawbacks such as lack of caching and increased size due to base64 encoding.

Advantages: fewer HTTP requests, possible bandwidth reduction for tiny files, avoids mixed‑content warnings on HTTPS.

Disadvantages: cannot be reused, not cacheable, requires decoding, increases size, and may pose security concerns.

Excellent URIs Should Not Change

A good URI remains stable over years. Changes are forced by site redesigns, expired domains, moved files, technology shifts, or the belief that URIs need not be permanent. Changing URIs breaks external links, bookmarks, and user trust.

Site redesign

Expired or confidential documents

File relocation

Switch from CGI to binary

Belief that only URNs need persistence

Designing stable URIs requires foresight, organization, and commitment.

URL as UI

URLs are part of the website UI and should be easy to remember, short, easy to type, reflect site structure, be predictable, and remain unchanged.

Memorable domain name

Short URL

Easy input

Visual hierarchy

Allow users to trim the last segment to reach a higher level

URL stability

Users typically guess URLs; keep them under 78 characters for email sharing and avoid case‑sensitivity issues.

Hash Fragment (#) in URLs

Specifies a position within the page; the browser scrolls to it.

Not sent to the server; only processed by the browser.

Changing the fragment does not reload the page but adds a history entry.

JavaScript can modify location.hash and listen to onhashchange.

Google ignores fragments unless using #!, which it converts to _escaped_fragment_ for indexing.

Flickr API URL Rules

Flickr image URLs follow patterns such as:

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 from small squares to original images.

Webpage URLs include user profiles, photostreams, individual photos, and sets, using either NSID or custom URLs.

Flickr also provides short URLs using Base58: http://flic.kr/p/{base58-photo-id}, which removes ambiguous characters.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

best practicesweb architectureWeb DevelopmentURIURL design
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.