301 vs 302 redirects
Both are Hypertext Transfer Protocol (HTTP) redirects. The server tells the browser to request a different Uniform Resource Locator (URL) using the Location response header.
Browser → GET /old
Server → 301 or 302, Location: /new
Browser → GET /newThe main difference is whether the move should be treated as permanent or temporary.
Quick comparison
| 301 — Moved Permanently | 302 — Found | |
|---|---|---|
| Meaning | The resource has permanently moved | The resource is temporarily available elsewhere |
| Browser caching | Commonly cached, even without explicit cache headers | Usually requested again unless caching is explicitly allowed |
| Future visits | Browser may go directly to the new URL | Browser normally checks the original URL again |
| Search engines | Usually replace the old URL with the new URL | Usually keep the old URL indexed |
| Typical use | Domain migration, canonical URL, permanent route change | Experiments, maintenance, temporary routing |
Browser behavior
301
- The browser follows the
Locationheader and loads the new URL. - It may cache the redirect and skip the original URL on later visits.
- A cached 301 can be difficult to undo because some users may continue redirecting without contacting the server.
302
- The browser follows the redirect for the current request.
- On a later visit, it normally requests the original URL again to discover where it should go now.
- This gives the server control to change or remove the redirect.
Rule of thumb: Use 301 only when you are confident the old URL should permanently point to the new one.
What happens to the HTTP method?
Historically, browsers may change a POST request to GET when following a 301 or 302 redirect.
- Use 303 See Other when a completed
POSTshould intentionally lead to aGET, such as after submitting a form. - Use 307 Temporary Redirect or 308 Permanent Redirect when the browser must preserve the original HTTP method and request body.
Performance and server cost
Every redirect that reaches the server introduces:
- an additional request and response,
- another network round trip before the final resource loads,
- extra work for the server, load balancer, logs, and monitoring systems.
The redirect response is small, but the added latency can be noticeable—especially on mobile or high-latency networks.
Cost difference
- A cached 301 can reduce future requests to the old server because the browser goes directly to the new URL.
- A 302 usually sends repeat visits through the old URL, so the redirecting service continues handling traffic.
- Serving redirects from a Content Delivery Network (CDN) or edge layer can reduce origin-server load and latency.
- Avoid redirect chains such as
/a → /b → /c; redirect directly to the final destination.
Analytics implications
An HTTP redirect happens before a web page loads, so client-side analytics code on the old URL does not run.
- Server or CDN logs can record the request to the old URL and the redirect response.
- Analytics on the destination page records the final page view.
- A cached 301 may bypass the old server entirely on repeat visits, so old-URL server logs will not capture every redirect.
- Preserve campaign parameters such as
utm_sourcein the destination URL, or campaign attribution may be lost. - Redirect chains create more places where query parameters and referrer information can be dropped.
- Exclude redirect responses from page-view metrics when combining server logs with client-side analytics, or traffic may be double-counted.
Analytics takeaway: Measure migrations at the destination and use server/CDN logs for redirect traffic. Do not rely on client-side analytics executing on the old URL.
Search Engine Optimization (SEO)
- Use 301 when the new URL should replace the old URL in search results and inherit its ranking signals.
- Use 302 when the move is temporary and the original URL should remain the canonical result.
- Search engines can reinterpret long-lived redirects, so the status code expresses intent but does not absolutely control indexing.
Interview answer
A 301 communicates a permanent move and may be cached by browsers, reducing future traffic to the old server. A 302 communicates a temporary move, so browsers generally revisit the original URL, which preserves routing control but continues generating redirect traffic and cost. For analytics, HTTP redirects do not execute client-side tracking on the old page; measure the final page and use server or CDN logs for the redirect itself.
Knowledge check — Q&A
Q: Why can a 301 be risky during a temporary migration?
Browsers may cache it and continue using the new URL even after the server removes the redirect.
Q: Which redirect costs the old server more over time?
Usually a 302, because repeat visits continue requesting the original URL.
Q: Does client-side analytics run on the redirecting URL?
No. The redirect response is handled before a page loads and executes JavaScript.
Q: When should 307 or 308 be used instead?
When the original HTTP method and request body must be preserved.
Q: What is the main redirect performance rule?
Redirect once, as close to the edge as practical, and point directly to the final URL.