api: YAML JSON TOON Database
version: 1.0.0
format: json
dataset:
  id: 22
  slug: http-redirect-status-codes
  title: HTTP Redirect Status Codes (3xx)
  description: "Comprehensive guide to HTTP 3xx redirect codes: when to use 301 vs 302 vs 307 vs 308, SEO implications, and browser behavior."
  summary: A guide to the 3xx redirection codes (300, 301, 302, 303, 304, 307 and 308) with when to use each, an example and notes, followed by best practices on redirect chains, caching and SEO.
  use_when:
    - You are moving a URL and need the right redirect status.
    - You need to know whether the request method is preserved.
  caveats:
    - 301 and 308 are cached by browsers for a long time, so test before deploying a permanent redirect.
    - Redirect chains slow pages and can lose the original method or body.
  related:
    - http-status-codes-complete
    - http-caching-guide
    - http-response-headers
    - http-status-code-best-practices
  category: HTTP Status Codes
  category_slug: http-status-codes
  tags: http,redirects,3xx,seo,permanent,temporary
  view_count: 0
  created_at: 1777673262
  updated_at: 1777673262
  entry_count: 17
  fields:
    - section: redirect_codes
      field: code
      type: integer
      example: "300"
    - section: redirect_codes
      field: name
      type: string
      example: Multiple Choices
    - section: redirect_codes
      field: when_to_use
      type: string
      example: Request has multiple possible responses; user o…
    - section: redirect_codes
      field: example
      type: string
      example: Server can serve content in multiple formats/la…
    - section: redirect_codes
      field: notes
      type: string
      example: Rarely used; most servers return 200 or 404 ins…
    - section: best_practices
      field: "*"
      type: array
      example: "[10 items]"
data:
  redirect_codes:
    - code: 300
      name: Multiple Choices
      when_to_use: Request has multiple possible responses; user or agent should choose one.
      example: Server can serve content in multiple formats/languages; returns list of options.
      notes: Rarely used; most servers return 200 or 404 instead
    - code: 301
      name: Moved Permanently
      when_to_use: Resource has new permanent URL; update bookmarks/links; SEO link equity transfers.
      example: "HTTP/1.1 301 Moved Permanently\\nLocation: https://example.com/new-path"
      notes: Cached by browsers and search engines; GET/HEAD may change to GET; POST becomes GET (not guaranteed)
    - code: 302
      name: Found (Temporary Redirect)
      when_to_use: Resource temporarily at different URI; keep original URL in future requests.
      example: "HTTP/1.1 302 Found\\nLocation: /login?next=/dashboard"
      notes: Original method may change to GET (historical); use 307 for method preservation
    - code: 303
      name: See Other
      when_to_use: Redirect after POST to GET (Post/Redirect/Get pattern); response to request is at different URI.
      example: "After form submission: HTTP/1.1 303 See Other\\nLocation: /thank-you"
      notes: Always converts request to GET regardless of original method
    - code: 304
      name: Not Modified
      when_to_use: Conditional GET request; resource cached and unchanged; no body sent.
      example: "Request: If-None-Match: \"abc123\"\\nResponse: HTTP/1.1 304 Not Modified"
      notes: Uses ETag or Last-Modified headers; saves bandwidth; browser uses cached copy
    - code: 307
      name: Temporary Redirect (Strict)
      when_to_use: Temporary redirect preserving HTTP method and body (POST stays POST).
      example: "HTTP/1.1 307 Temporary Redirect\\nLocation: https://api.example.com/v2/endpoint"
      notes: Must not change method; modern replacement for 302 when method preservation matters
    - code: 308
      name: Permanent Redirect (Strict)
      when_to_use: Permanent redirect preserving HTTP method (POST→POST); SEO-safe permanent.
      example: "HTTP/1.1 308 Permanent Redirect\\nLocation: https://example.com/new-api-endpoint"
      notes: Like 301 but method/body preserved; RFC 7538; widely supported in modern browsers
  best_practices:
    - Use 301 for permanent URL changes (site migration, HTTP→HTTPS upgrade)
    - Use 302 for temporary A/B tests, maintenance pages, short-term moves
    - Use 307 when you need to preserve POST data during temporary redirect
    - Use 308 for permanent API endpoint migration where method must stay same
    - Always include Location header with absolute URL for 301/302/307/308
    - Avoid redirect chains (max 1-2 hops); each redirect adds latency
    - "Set Cache-Control headers appropriately: long max-age for 301, no-cache for 302"
    - Test with curl -I to verify Location header and status code
    - "For SEO: 301 passes PageRank; 302 does not (usually)"
    - Never redirect POST to GET unless using 303 (Post/Redirect/Get pattern)
