307 Temporary Redirect
Fault: Neither
TL;DR
Temporary redirect that preserves the request method.
The request should be repeated with another URL, but future requests should still use the original URL.
What This Error Means
The request should be repeated with another URL, but future requests should still use the original URL.
Temporary redirect that preserves the request method.
Common Causes
- Temporary server maintenance
- Load balancing
- Temporary URL change
How to Fix It (For Visitors)
- Browser should automatically redirect
How to Fix It (For Developers/Admins)
- Use instead of 302 to preserve HTTP method
- Set Location header
Code Examples
Here's how to return a 307 status code in various programming languages:
Python (Flask)
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/endpoint')
def endpoint():
return jsonify({"message": "Temporary Redirect"}), 307
Node.js (Express)
const express = require('express');
const app = express();
app.get('/endpoint', (req, res) => {
res.status(307).json({ message: 'Temporary Redirect' });
});
PHP
<?php
http_response_code(307);
header('Content-Type: application/json');
echo json_encode(['message' => 'Temporary Redirect']);
?>
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(307)
json.NewEncoder(w).Encode(map[string]string{
"message": "Temporary Redirect",
})
}
Java (Spring Boot)
@GetMapping("/endpoint")
public ResponseEntity<Map<String, String>> endpoint() {
Map<String, String> response = new HashMap<>();
response.put("message", "Temporary Redirect");
return ResponseEntity.status(307).body(response);
}
Ruby (Sinatra)
get '/endpoint' do
status 307
json message: 'Temporary Redirect'
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.7.