How an HTTP redirect works
A website, CDN or reverse proxy sends a redirect response instead of the requested content. The response contains a 3xx status code and usually a Location field in its HTTP headers:
HTTP/1.1 302 Found
Location: https://example.com/new-page
The client resolves the new URL and makes a separate HTTP request. The server doesn’t fetch the destination on the client’s behalf. Each redirect therefore adds another request, response and network round trip.
The Location value can be an absolute URL or a relative reference such as /new-page. Clients often follow redirects automatically, but command-line tools and libraries may require an option or setting.
Common redirect codes
The code tells the client whether the move is permanent and whether it must preserve the original request method and body.
| Code | Meaning | Method behavior |
|---|---|---|
| 301 / 308 | Permanent move | 308 preserves; 301 may change POST to GET |
| 302 / 307 | Temporary move | 307 preserves; 302 may change POST to GET |
| 303 | See another resource | Usually followed with GET |
Not every 3xx status is a redirect. For example, 304 Not Modified tells a client to use its cached response and normally has no redirect destination.
Redirects through proxies
Your client sends the first request through the proxy, reads the redirect and then sends a new request to the destination. If the proxy remains configured, the redirected request normally uses it too. Redirect handling belongs to the browser, crawler or HTTP library rather than the proxy itself.
A per-request rotating proxy may assign another exit IP between hops. A sticky session can keep the exit IP consistent when a redirect flow is sensitive to IP changes. Separately, your client must store and resend relevant cookies through its cookie jar across redirect hops.
Handling redirects safely
- Set a hop limit. Five to ten hops is a common client limit and prevents endless redirect loops.
- Resolve relative locations. Build them against the URL that returned the redirect.
- Apply the method rules. Don’t resend a POST body after a 303, but preserve it for 307 and 308.
- Protect credentials. Don’t blindly forward
Authorizationor cookies when a redirect changes the hostname. - Log the chain. Record every status and destination so you can find loops, unexpected domains or repeated HTTP-to-HTTPS changes.
FAQ
What is the difference between a 301 and 302 redirect?
A 301 says the resource moved permanently, while a 302 says the move is temporary. Clients may change a POST to GET for either code; use 308 or 307 when preserving the method and body is required.
Why do I get a too many redirects error?
It usually means two URLs redirect to each other or the site keeps rejecting a session cookie. Conflicting HTTP-to-HTTPS rules, hostname rules and stale cookies are common causes.
Do proxies follow HTTP redirects automatically?
No. The browser or HTTP library decides whether to follow them. A proxy transports each request and response but doesn’t normally control the redirect policy.