What are redirection status codes?

Free preview 5 min to read

The detour sign of the web

Imagine you drive to your favorite restaurant, but there's a sign on the door: "We moved to 123 Main Street." You don't give up: you just follow the new address. That's what a 3xx redirection does on the web.

When a server responds with a 3xx status code, it's telling the client: "What you're looking for isn't here: but I'll tell you where to find it." The client (usually a browser) then automatically follows the new location.


How redirects work

A redirect response has two essential parts:

  1. A 3xx status code: tells the client this is a redirect
  2. A Location header: tells the client where to go next
HTTP/1.1 301 Moved Permanently
Location: https://www.example.com/new-page

The browser reads the Location header and automatically makes a new request to that URL. The user usually doesn't even notice: it happens in milliseconds.


The redirect flow

Here's what happens step by step:

Client                          Server
  |                               |
  |  GET /old-page HTTP/1.1       |
  |------------------------------>|
  |                               |
  |  301 Moved Permanently        |
  |  Location: /new-page          |
  |<------------------------------|
  |                               |
  |  GET /new-page HTTP/1.1       |
  |------------------------------>|
  |                               |
  |  200 OK                       |
  |  (actual content)             |
  |<------------------------------|

Notice: the client makes two requests. The first gets the redirect, the second gets the actual content. This is why excessive redirects slow down page loads.


The 3xx family at a glance

Not all redirects are the same. The 3xx range includes several codes, each with different behavior:

Code Name Key Behavior
301 Moved Permanently Permanent redirect: browsers cache it
302 Found Temporary redirect: check again next time
303 See Other Redirect after POST: always use GET
304 Not Modified Not a redirect: use your cached copy
307 Temporary Redirect Like 302, but preserves the HTTP method
308 Permanent Redirect Like 301, but preserves the HTTP method

We'll cover each of these in detail throughout this course.


Why redirects matter

Redirects are everywhere in web development. Here are the most common use cases:

Moving content: When you restructure a website, old URLs need to point to new ones. Without redirects, users and search engines would hit dead ends.

Enforcing HTTPS: Most sites redirect http:// requests to https:// automatically. That's a redirect.

After form submissions: When a user submits a form (POST), you redirect them to a confirmation page (GET). This prevents duplicate submissions if they refresh the page.

Authentication flows: After signing in, users are redirected to their dashboard. After signing out, they're redirected to the home page.

Domain changes: When a company rebrands, old-domain.com redirects to new-domain.com.


Redirect chains and loops

Two problems can arise with redirects:

Redirect chains happen when one redirect leads to another, which leads to another:

/page-a → /page-b → /page-c → /page-d (final destination)

Each hop adds latency. Search engines may stop following after a few hops. Keep chains as short as possible: ideally just one redirect.

Redirect loops happen when redirects form a circle:

/page-a → /page-b → /page-a → /page-b → ...

Browsers detect this and show an error like "This page isn't working: too many redirects." This is a common bug in misconfigured applications.


Temporary vs. permanent

The most fundamental distinction in 3xx codes is whether a redirect is temporary or permanent:

Aspect Temporary (302, 307) Permanent (301, 308)
Meaning "Use this other URL for now" "Use this other URL forever"
Caching Browser checks the original URL each time Browser remembers and skips the original URL
SEO Search engines keep indexing the original URL Search engines transfer ranking to the new URL
Use case Maintenance, A/B testing, feature flags URL restructuring, domain migration

Choosing the wrong type can cause real problems: a permanent redirect when you meant temporary can be very hard to undo, since browsers cache them aggressively.


Summary

Concept Key Point
3xx codes Tell the client to look somewhere else for the resource
Location header Contains the URL the client should follow
Redirect flow Client makes two requests: one gets the redirect, one gets the content
Temporary vs. permanent Temporary: check again next time. Permanent: update your records
Redirect chains Multiple hops: keep them short
Redirect loops Circular redirects: a bug that browsers will catch and report
Common uses HTTPS enforcement, post-form redirects, URL restructuring, auth flows
Lesson 1 of 7 · free

Keep going with lesson 2

301 Moved permanently

Covers 301 Moved Permanently, its aggressive browser caching, SEO transfer, common uses and the POST to GET change.

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

Type to start searching...