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
One hop
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.
Follow the chain
-L follows redirects. Filter the output to the lines that matter.
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.
A redirect to sign in
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.
Follow an old link
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
| Command | What it does |
|---|---|
301 Moved Permanently | Moved for good. Browsers remember it |
302 Found | Go there this time, often to sign in |
303 See Other | After a POST, fetch the result with GET |
307, 308 | Like 302 and 301, but keep the method and body |
What a defender takes away
- 1Redirects are a status code plus a Location header.
- 2
curl -sILshows every hop, not just the end. - 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.