What is a URL?

Free preview 5 min to read

The address of the web

Every time you click a link, type an address in your browser, or submit a form: you're using a URL. It's so common that most people never think about what it is.

A URL (Uniform Resource Locator) is the address that tells your browser where to find a specific resource on the internet. Just like a street address tells a delivery driver where to go, a URL tells the browser which server to contact, what to ask for, and how to ask for it.


URL vs URI vs URN

You'll sometimes see these terms used interchangeably, but they have distinct meanings:

Term Stands For Purpose Example
URI Uniform Resource Identifier A generic identifier for any resource Any URL or URN
URL Uniform Resource Locator Identifies a resource AND tells you how to locate it https://example.com/page
URN Uniform Resource Name Identifies a resource by name, without location urn:isbn:0451450523

Think of it this way:

  • A URN is like a person's name: it identifies them but doesn't tell you where they are
  • A URL is like their home address: it identifies them AND tells you how to find them
  • A URI is the umbrella term that covers both

In practice, almost everything on the web is a URL. When someone says "URI" in web development, they usually mean a URL.


Anatomy of a URL

A URL is made up of several components, each with a specific purpose:

https://www.example.com:443/catalog/courses?level=intern&sort=name#section-2
└─┬──┘  └──────┬──────┘└┬┘└──────┬────────┘└──────────┬──────────┘└───┬────┘
scheme       host     port     path            query string       fragment

Let's break this down:

Component Example Purpose
Scheme https The protocol to use
Host www.example.com Which server to contact
Port 443 Which door on the server
Path /catalog/courses Which resource to request
Query String ?level=intern&sort=name Additional parameters
Fragment #section-2 A specific section within the page

Not all components are required. A web address can be just a scheme and a host:

https://example.com

Absolute vs relative URLs

URLs come in two forms:

Absolute URLs

Include the full address: scheme, host, and path:

https://www.example.com/catalog/courses

Used when linking to external sites or when the full address is needed (emails, APIs, redirects).

Relative URLs

Omit the scheme and host, using only the path (relative to the current page):

<!-- On https://www.example.com/catalog/roadmap -->
<a href="/catalog/courses">Courses</a>        <!-- Absolute path -->
<a href="courses">Courses</a>                  <!-- → /catalog/courses -->
<a href="../about">About</a>                   <!-- → /about -->
Type Example When to Use
Absolute https://example.com/page External links, APIs, emails
Root-relative /catalog/courses Internal navigation (most common in Rails)
Relative courses or ../about Relative to the current page

In Rails, you'll mostly use root-relative paths generated by route helpers like catalog_course_path.


Why URLs matter for developers

Understanding URL anatomy isn't just academic: it's essential for web development:

  • Routing: Rails maps URLs to controller actions. Every route you define is a URL pattern.
  • SEO: Search engines use URLs to understand your site's structure. Readable URLs help people and crawlers understand a page, though they are a minor ranking signal.
  • Security: Sensitive data in URLs (like tokens in query strings) can leak through browser history, server logs, and referrer headers.
  • Debugging: When something goes wrong, the URL is the first thing you check: wrong path? Missing parameter? Wrong protocol?
  • APIs: RESTful APIs are built entirely around well-structured URLs.
# In Rails, routes define URL patterns:
# GET /catalog/courses/:slug → Catalog::CoursesController#show

# The URL tells Rails:
# - HTTP verb: GET (safe, read-only)
# - Controller: Catalog::CoursesController
# - Action: show
# - Parameter: slug = "url-anatomy"

A brief history

Tim Berners-Lee created URLs around 1990 as part of the World Wide Web. RFC 1738 first specified them in 1994; today's rules come from RFC 3986 and the WHATWG URL Standard that browsers follow.

The original design was intentionally human-readable: you should be able to look at a URL and have a rough idea of what it points to. This principle still guides good URL design today:

# Good: descriptive, readable
https://example.com/catalog/courses/url-anatomy

# Bad: opaque, meaningless
https://example.com/p?id=48372&v=2&ref=x

Summary

Concept Key Point
URL Uniform Resource Locator: the complete address to find a resource on the web
URI vs URL vs URN URI is the umbrella term; URL includes location; URN is name-only
Components Scheme, host, port, path, query string, and fragment
Absolute vs Relative Absolute includes the full address; relative is based on the current page
Why It Matters Routing, SEO, security, debugging, and API design all depend on URLs
Good URL Design Human-readable, descriptive, and logically structured
Lesson 1 of 7 · free

Keep going with lesson 2

Scheme and protocol

Explains how the scheme selects a protocol, compares HTTP and HTTPS, and covers other schemes and Rails helpers.

A free account also gives you the quizzes, your progress and notes, and the discussion.

Type to start searching...