A redirect tells the client to request a different URL. The status code decides whether the move is permanent and whether the client may change the method, and browsers and caches treat the codes differently, which is where redirect bugs come from.
Before you start
You should understand HTTP methods and status classes. This article covers the common redirect codes and their caching behavior.
Step-by-step walkthrough
Step 1: Choose permanent or temporary
301 is a permanent move and is cached aggressively, so a mistaken permanent redirect is hard to undo. 302 is temporary and is not cached the same way. Prefer 302 when unsure, and reserve 301 for a URL that will never come back.
Step 2: Watch what happens to the method
Historically 301 and 302 allowed clients to change a POST into a GET, which loses the body. 307 and 308 preserve the method and body, so use them when the original method must be kept. 308 is the permanent counterpart of 307.
Step 3: Prevent loops and caches
A redirect chain that returns to a URL it already visited creates a loop, which the browser aborts after a limit. Because 301 and 308 are cached, stale redirects persist in client caches, so test with a fresh cache and keep the chain short.
Worked scenario
The response shows the target and the code that governs caching.
HTTP/1.1 301 Moved Permanently
Location: https://example.com/new-path
HTTP/1.1 307 Temporary Redirect
Location: https://example.com/processWalk through the example
The 301 tells the client and caches that the old URL is permanently replaced, so the redirect is stored. The 307 sends the client to the same path but preserves the method and body, which matters for a form submission. Using 301 for the second case could turn the POST into a GET in older clients.
Common mistake
Using 301 when the move might be temporary, then being unable to revert because caches hold it. Another is a redirect chain that loops or grows long, which slows every visit and can break entirely.
Verify the behavior
Request the old URL and confirm the status, Location header and preservation of method for 307/308. Follow the chain and confirm it terminates in one or two hops. Test with an empty cache after changing a redirect to confirm the new behavior.
Interview exercise
Why do 307 and 308 exist when 301 and 302 already redirect?
Answer and reasoning
Because older clients were allowed to change the method on a 301 or 302, turning a POST into a GET and dropping the body. 307 and 308 forbid that change and require the same method and body, so they are the correct choice for redirecting a method-sensitive request while preserving temporary or permanent semantics.
Continue learning
Compare status handling in HTTP status classes and method semantics in HTTP method semantics. Read the MDN redirects documentation and try the Networking interview questions.