warning http

HTTP 302 Found

Understanding HTTP 302 Found status code - the requested resource temporarily resides at a different URI. Future requests should still use the original URI.

What It Means

HTTP 302 Found indicates that the requested resource temporarily resides under a different URI. Since the redirection might be altered on occasion, the client should continue to use the original URI for future requests.

Unlike 301, search engines will not transfer SEO ranking to the new URL — they’ll keep indexing the original URL.

Important caveat: Most browsers change POST requests to GET requests when following a 302 redirect. If you need to preserve the HTTP method, use 307 instead.

Common Causes

  • Temporary URL changes during maintenance or A/B testing
  • Redirecting to a login page when authentication is required
  • Redirecting after form submission (Post/Redirect/Get pattern)
  • Geo-based or language-based redirects
  • Load balancing across temporary endpoints
  • OAuth authorization flows

How to Fix

Express.js

// Post/Redirect/Get pattern
app.post('/contact', async (req, res) => {
  await saveContactForm(req.body);
  res.redirect(302, '/contact/thank-you');
});

// Redirect to login
app.get('/dashboard', (req, res, next) => {
  if (!req.isAuthenticated()) {
    return res.redirect(302, '/login?returnTo=/dashboard');
  }
  next();
});

Nginx

# Temporary redirect during maintenance
location /api/v2 {
    return 302 https://maintenance.example.com/api/v2;
}

Python Flask

from flask import redirect, url_for

@app.route('/old-feature')
def old_feature():
    return redirect(url_for('new_feature'), code=302)

@app.route('/dashboard')
@login_required
def dashboard():
    # Flask-Login automatically redirects to login with 302
    pass

Client-side handling

// fetch follows 302 redirects automatically
const response = await fetch('/old-endpoint');
// response.url will be the final URL after redirect

// To detect a redirect occurred
if (response.redirected) {
  console.log('Was redirected to:', response.url);
}

// To prevent automatic redirect following
const response = await fetch('/old-endpoint', { redirect: 'manual' });
if (response.status === 302) {
  const newUrl = response.headers.get('Location');
  console.log('Redirect to:', newUrl);
}
  • HTTP 301 - Moved Permanently: Use for permanent URL changes that transfer SEO.
  • HTTP 307 - Temporary Redirect: Like 302 but guarantees the HTTP method is preserved.
  • HTTP 308 - Permanent Redirect: Like 301 but guarantees the HTTP method is preserved.