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