← Back to Chapters

308 Permanent Redirect

? 308 Permanent Redirect

? Quick Overview

The 308 Permanent Redirect HTTP status code indicates that a requested resource has been permanently moved to a new URL, and all future requests should use the new URL. Unlike 301, it preserves the original HTTP method and request body.

? Key Concepts

  • Belongs to the 3xx Redirection class
  • Indicates a permanent URL change
  • Preserves HTTP method (GET, POST, PUT, etc.)
  • Client must reuse the same request body
  • Introduced in HTTP/1.1 RFC 7538

? Syntax / Theory

When a server responds with status code 308, it must include a Location header containing the new permanent URL.

? View Code Example
// HTTP response indicating permanent redirect with method preserved
HTTP/1.1 308 Permanent Redirect
Location: https://example.com/new-endpoint

? Code Example(s)

? View Code Example
// Express.js example sending a 308 redirect
app.post("/old-api", (req, res) => {
res.redirect(308, "/new-api");
});

? Live Output / Explanation

What Happens?

  • Client receives status code 308
  • Browser or client keeps the same HTTP method
  • Request body is sent again to the new URL
  • Future requests should directly use the new URL

? Interactive Example

Below demonstrates how a POST request is preserved during a 308 redirect, unlike 301 or 302 which may convert it to GET.

? View Code Example
// Fetch API showing method preserved on 308 redirect
fetch("/old-endpoint", {
method: "POST",
body: JSON.stringify({name:"User"})
});
Ready to start
 

? Use Cases

  • API version upgrades without breaking POST requests
  • Permanent migration of form submission endpoints
  • Secure endpoint restructuring
  • RESTful service URL normalization

✅ Tips & Best Practices

  • Use 308 instead of 301 for APIs handling POST/PUT
  • Always include the Location header
  • Ensure idempotency where possible
  • Test client behavior for redirects

? Try It Yourself

  • Create a POST endpoint and redirect it using 308
  • Compare behavior with 301 and 302
  • Inspect request method in browser dev tools
  • Test with curl using -L flag