HTTP
302 - Found
Seeing a 302 Found means the resource temporarily moved to a new URL—follow the Location header for this request, but keep using the original URL for future requests since it's temporary. This client-side redirect (3xx) is the classic temporary redirect, though browsers often change POST to GET. Most common when resources are temporarily relocated, maintenance mode redirects users, or A/B testing routes traffic, but also appears when temporary redirects are configured, maintenance windows redirect, or temporary location changes occur.
#Common Causes
- →Frontend: Resource temporarily moved. Maintenance mode active. A/B testing redirects traffic. Temporary location change.
- →Backend: Temporary redirect configured. Resource temporarily relocated. Maintenance mode redirect. A/B testing logic. Temporary URL change.
- →Infrastructure: Load balancer temporary redirect. CDN temporary routing. Reverse proxy temporary redirect. Maintenance mode active.
✓Solutions
- 1Step 1: Diagnose - Check DevTools Network tab Location header—302 responses show temporary redirect URL. Review redirect chain. Check if redirect is actually temporary.
- 2Step 2: Diagnose - Server logs show redirect configuration. Review temporary redirect rules. Check if resource actually moved. Verify redirect is temporary.
- 3Step 3: Fix - Client-side: Follow Location header for this request. Keep original URL for future requests. Handle redirect in application logic. Don't cache redirect.
- 4Step 4: Fix - Server-side: Configure 302 redirect with correct Location header. Ensure redirect is actually temporary. Set proper cache headers. Use 307 if method must be preserved.
- 5Step 5: Fix - Infrastructure: Configure temporary redirects properly. Review load balancer routing. Update CDN temporary redirects. Check maintenance mode.
</>Code Examples
Fetch API: Handle 302 Temporary Redirects
1// Client-side: Handle 302 temporary redirects
2async function fetchWithTemporaryRedirect(url) {
3 // Option 1: Let fetch follow redirect automatically
4 const response = await fetch(url, { redirect: 'follow' });
5 return response.json();
6}
7
8// Option 2: Manual redirect handling
9async function fetchWithManualRedirect(url) {
10 let response = await fetch(url, { redirect: 'manual' });
11
12 if (response.status === 302) {
13 const newUrl = response.headers.get('Location');
14 console.log('Temporary redirect to:', newUrl);
15
16 // Follow redirect for this request only
17 // Don't update stored URL - it's temporary
18 response = await fetch(newUrl);
19 }
20
21 return response.json();
22}
23
24// Handle redirect chain
25async function fetchWithRedirectChain(url, maxRedirects = 5) {
26 let currentUrl = url;
27 let redirectCount = 0;
28
29 while (redirectCount < maxRedirects) {
30 const response = await fetch(currentUrl, { redirect: 'manual' });
31
32 if (response.status === 302) {
33 currentUrl = response.headers.get('Location');
34 redirectCount++;
35 continue;
36 }
37
38 return response.json();
39 }
40
41 throw new Error('Too many redirects');
42}
43
44// Note: 302 may change POST to GET in some browsers
45// Use 307 if you need to preserve methodExpress.js: Configure 302 Temporary Redirects
1// Server-side: Return 302 for temporary redirects
2const express = require('express');
3const app = express();
4
5// Temporary redirect
6app.get('/api/temp-endpoint', (req, res) => {
7 // Resource temporarily moved
8 res.redirect(302, '/api/temporary-location');
9});
10
11// Maintenance mode redirect
12app.use((req, res, next) => {
13 if (process.env.MAINTENANCE_MODE === 'true') {
14 return res.redirect(302, '/maintenance');
15 }
16 next();
17});
18
19// A/B testing redirect
20app.get('/api/feature', (req, res) => {
21 const variant = Math.random() > 0.5 ? 'a' : 'b';
22 res.redirect(302, `/api/feature/${variant}`);
23});
24
25// Temporary location change
26app.get('/api/old-location', (req, res) => {
27 res.status(302)
28 .set('Location', '/api/new-location')
29 .set('Cache-Control', 'no-cache') // Don't cache temporary redirect
30 .end();
31});
32
33// Temporary redirect with query params
34app.get('/api/search', (req, res) => {
35 // Temporarily redirect to new search endpoint
36 const query = req.query.q;
37 res.redirect(302, `/api/v2/search?q=${query}`);
38});Nginx: Configure 302 Temporary Redirects
1# Nginx: Configure temporary redirects
2server {
3 listen 80;
4 server_name api.example.com;
5
6 # Temporary redirect
7 location /api/temp-endpoint {
8 return 302 /api/temporary-location$is_args$args;
9 }
10
11 # Maintenance mode redirect
12 location / {
13 if ($maintenance_mode = 1) {
14 return 302 /maintenance;
15 }
16 proxy_pass http://backend;
17 }
18
19 # Temporary redirect with no cache
20 location /api/old-location {
21 return 302 /api/new-location$is_args$args;
22 add_header Cache-Control "no-cache" always;
23 }
24
25 # A/B testing redirect
26 location /api/feature {
27 set $variant "a";
28 if ($arg_test = "b") {
29 set $variant "b";
30 }
31 return 302 /api/feature/$variant$is_args$args;
32 }
33
34 # Or use rewrite for temporary redirect
35 location /api/legacy {
36 rewrite ^/api/legacy(.*)$ /api/temp$1 redirect;
37 }
38}↗Related Errors
Provider Information
This error code is specific to HTTP services. For more information, refer to the official HTTP documentation.