302 Found
Fault: Neither
TL;DR
Resource temporarily moved but may return to original URL.
The resource temporarily resides at a different URL.
What This Error Means
The resource temporarily resides at a different URL.
Resource temporarily moved but may return to original URL.
Common Causes
- Temporary redirect
- A/B testing
- Maintenance mode redirect
How to Fix It (For Visitors)
- Browser should automatically redirect
How to Fix It (For Developers/Admins)
- Use 307 instead for temporary redirects that preserve method
- Set Location header
Code Examples
Here's how to return a 302 status code in various programming languages:
Python (Flask)
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/endpoint')
def endpoint():
return jsonify({"message": "Found"}), 302
Node.js (Express)
const express = require('express');
const app = express();
app.get('/endpoint', (req, res) => {
res.status(302).json({ message: 'Found' });
});
PHP
<?php
http_response_code(302);
header('Content-Type: application/json');
echo json_encode(['message' => 'Found']);
?>
Go
package main
import (
"encoding/json"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(302)
json.NewEncoder(w).Encode(map[string]string{
"message": "Found",
})
}
Java (Spring Boot)
@GetMapping("/endpoint")
public ResponseEntity<Map<String, String>> endpoint() {
Map<String, String> response = new HashMap<>();
response.put("message", "Found");
return ResponseEntity.status(302).body(response);
}
Ruby (Sinatra)
get '/endpoint' do
status 302
json message: 'Found'
end
Browser Compatibility
| Browser | Support | Notes |
|---|---|---|
| Chrome | ✓ Full Support | All versions |
| Firefox | ✓ Full Support | All versions |
| Safari | ✓ Full Support | All versions |
| Edge | ✓ Full Support | All versions |
Official Specification
This status code is defined in RFC 7231 Section 6.4.3.