- Home
- HTTP Status Codes
- HTTP 302 Found: Temporary Redirect
Status Code
HTTP 302 Found: Temporary Redirect
Learn what 302 redirect means, when to use temporary vs permanent redirects, and how 302 differs from 301, 307, and 308.
TL;DR: 302 Found means temporary redirect. The resource is at a different URL for now, but use the original URL for future requests.
What is 302 Found?
A 302 redirect tells clients the resource is temporarily at a different location. Unlike 301, the original URL remains the “real” address.
GET /promo HTTP/1.1
Host: example.com
```text
```http
HTTP/1.1 302 Found
Location: /current-sale
When to Use 302
- A/B testing - Temporarily redirect to test variants
- Maintenance - Redirect to status page during downtime
- Geolocation - Redirect to regional site
- Login redirect - Send to login, then back to original page
- Temporary promotions -
/sale→/black-friday-2024
301 vs 302
| Aspect | 301 Permanent | 302 Temporary |
|---|---|---|
| Meaning | URL changed forever | URL temporarily different |
| Caching | Browsers cache aggressively | May not cache |
| SEO | Transfers link equity | Keeps original indexed |
| Bookmarks | Should update | Keep original |
Implementation
Express.js
// Temporary redirect (302 is default)
app.get('/promo', (req, res) => {
res.redirect('/current-sale')
})
// Explicit 302
app.get('/promo', (req, res) => {
res.redirect(302, '/current-sale')
})
// Login redirect pattern
app.get('/dashboard', (req, res, next) => {
if (!req.user) {
return res.redirect(`/login?returnTo=${req.url}`)
}
next()
})
```nginx
### Nginx
```nginx
location = /promo {
return 302 /current-sale;
}
302 vs 307
Both are temporary, but differ in method handling:
# 302: Browser MAY change POST to GET (legacy)
POST /form → 302 → GET /result
# 307: Browser MUST keep POST
POST /form → 307 → POST /new-form
```text
Use **307** when you need to preserve POST/PUT/DELETE methods.
## Common Mistakes
```javascript
// ❌ Wrong: Using 302 for permanent URL changes
app.get('/old-blog/*', (req, res) => {
res.redirect('/new-blog' + req.path) // Should be 301
})
// ✅ Correct: 301 for permanent changes
app.get('/old-blog/*', (req, res) => {
res.redirect(301, '/new-blog' + req.path)
})
Related
- 301 Moved Permanently - Permanent redirect
- 307 Temporary Redirect - Temporary, preserves method
- 303 See Other - Redirect after POST
- Location header - Redirect target
The Post/Redirect/Get Pattern
The most important practical use of 302 is the Post/Redirect/Get (PRG) pattern, which prevents duplicate form submissions. When a user submits a form, the server processes it and responds with a 302 redirect to a results page. The browser follows the redirect with a GET request. If the user then refreshes the page, they refresh the GET request (the results page), not the original POST, so the form is not resubmitted.
Without PRG, refreshing after a form submission triggers a browser warning (“Resend form data?”) and potentially resubmits the form, creating duplicate orders, duplicate comments, or duplicate database records. PRG eliminates this problem entirely.
The redirect target is typically a confirmation page or the updated resource. For example, after creating a new blog post, the server processes the POST, saves the post, and redirects to GET /posts/123. The user sees the new post, and refreshing the page simply reloads the post without creating another one.
302 is the correct status code for PRG because the redirect is genuinely temporary — the form submission URL is still valid for future submissions. Using 301 would cause browsers to cache the redirect and skip the POST entirely on subsequent visits, which would break the form. The method change behavior of 302 (POST becomes GET on redirect) is actually the desired behavior for PRG, which is why 302 is preferred over 307 for this pattern.
Frequently Asked Questions
What does 302 redirect mean?
A 302 tells browsers the resource is temporarily at a different URL. Keep using the original URL—it will work again later.
What is the difference between 301 and 302?
301 is permanent (update bookmarks, SEO transfers). 302 is temporary (keep original URL, no SEO transfer).
Does 302 affect SEO?
Yes, 302 tells search engines to keep indexing the original URL. Use 301 for permanent moves to transfer SEO value.
When should I use 302 vs 307?
302 may change POST to GET (legacy behavior). 307 guarantees method preservation. Use 307 for POST redirects.