Opscraft
HTTP & status codes · Lesson 3 of 9 · 3 min read

3xx redirection and caching

Redirect codes

Code Permanent? Method on redirect Use
301 Moved Permanently Yes Browsers may change POST → GET Canonical URLs, domain moves, HTTP → HTTPS
302 Found No May change POST → GET Temporary redirects (login flows)
303 See Other No Always GET After a POST form, redirect to a result page
307 Temporary Redirect No Keeps method and body Temporary redirect of APIs/POSTs
308 Permanent Redirect Yes Keeps method and body Permanent moves of APIs
  • 301s are cached by browsers, sometimes indefinitely — a wrong 301 is hard to undo. Test with 302 first.
  • HTTP → HTTPS on an ALB: a port-80 listener whose default action is a redirect to HTTPS with 301 (alb.ingress.kubernetes.io/ssl-redirect: '443' with the LB Controller).
  • Redirect loops (ERR_TOO_MANY_REDIRECTS) often come from TLS terminating at the LB: the app sees plain HTTP, redirects to HTTPS, the LB forwards as HTTP again... Fix: the app must trust X-Forwarded-Proto.
  • Follow redirects in curl with -L.
Enlarge diagrambrowserhttps://shop…ALBends TLSappsees plain HTTPFixMake the app trust X-Forwarded-Proto: https from the load balancer, or let the load balancer do the HTTP →HTTPS redirect itself.HTTPSHTTP301 → https://301 → https://… and round again: ERR_TOO_MANY_REDIRECTS
Figure 1. The classic redirect loop: TLS ends at the load balancer, so the app thinks every request is plain HTTP and keeps redirecting to HTTPS.
Swipe sideways to see all of it, or tap to open it full screen.

304 Not Modified

Conditional requests save bandwidth: the client sends If-None-Match: "<etag>" (or If-Modified-Since); if unchanged, the server answers 304 with no body and the client uses its cached copy. CDNs and browsers rely on it heavily.

Enlarge diagramBrowser / CDNhas a cached copyServerGET /logo.png · If-None-Match: "v7"304 Not Modified (no body): use your copyGET /logo.png · If-None-Match: "v7"200 OK · ETag: "v8" + the new image
Figure 2. A conditional request: the client says which version it has, and if nothing changed the server sends 304 with no body.
Swipe sideways to see all of it, or tap to open it full screen.