Unit 2: URLs, methods and redirects · Lesson 3 of 5 · 15 min

Redirects

A 3xx status and a Location header send the client somewhere else.

mission

You are
The analyst reviewing the shop.
Situation
Old links to the shop still circulate in emails. Marketing asks where each one ends up.
Goal
Follow every old link hop by hop and record where it lands.
Hand in
A chain of status codes and locations for each old link.

Redirects as rail switches

01

One hop

learner@web-lab
curl -sI http://127.0.0.1:8000/home
HTTP/1.1 301 Moved Permanently
Server: shop/1.4
Date: Wed, 14 Oct 2026 09:00:00 GMT
Content-Length: 0
Location: /

you should see 301 and a Location header. No body.

02

Follow the chain

-L follows redirects. Filter the output to the lines that matter.

learner@web-lab
curl -sIL http://127.0.0.1:8000/home | grep -E '^HTTP|^Location'
HTTP/1.1 301 Moved Permanently
Location: /
HTTP/1.1 200 OK

you should see Two status lines: the redirect and the page it leads to.

03

A redirect to sign in

learner@web-lab
curl -sI http://127.0.0.1:8000/account | grep -E '^HTTP|^Location'
HTTP/1.1 302 Found
Location: /login

you should see 302 to the sign-in page. Private pages send anonymous visitors away instead of showing data.

04

Follow an old link

learner@web-lab
curl -sI http://127.0.0.1:8000/old-shop | grep -E '^HTTP|^Location'
HTTP/1.1 301 Moved Permanently
Location: /shop

you should see 301 to /shop. Browsers cache permanent redirects, so a wrong one is hard to undo.

defender tip List every redirect when you map an app. Each is a place where the destination should be fixed, never taken from the request.

Redirect codes

CommandWhat it does
301 Moved PermanentlyMoved for good. Browsers remember it
302 FoundGo there this time, often to sign in
303 See OtherAfter a POST, fetch the result with GET
307, 308Like 302 and 301, but keep the method and body

What a defender takes away

  1. 1Redirects are a status code plus a Location header.
  2. 2curl -sIL shows every hop, not just the end.
  3. 3301 is cached by browsers, so a wrong one is hard to undo.

Questions

0 of 3 solved

Answer each one from what you find on your lab machine.