Skip to content

Latest commit

 

History

History
56 lines (37 loc) · 1.54 KB

File metadata and controls

56 lines (37 loc) · 1.54 KB

Both 301 and 302 are HTTP redirect status codes, but they differ in meaning and use case.


🔹 301 Moved Permanently

  • Meaning: The resource has been permanently moved to a new URL.

  • Effect on browsers & SEO:

    • Browsers (and clients) cache the redirect.
    • Search engines update their index to the new URL.
    • Any "link juice" (SEO ranking) is passed to the new URL.
  • Use case:

    • When a page/endpoint is permanently moved.

    • Example:

      GET /old-page
      → 301 Moved Permanently → Location: /new-page
      

      Now future requests will directly go to /new-page.


🔹 302 Found (Temporary Redirect)

  • Meaning: The resource has been temporarily moved to a different URL.

  • Effect on browsers & SEO:

    • Browsers do not cache permanently.
    • Search engines do not update their index (they keep old URL).
    • Link authority usually stays with the old URL.
  • Use case:

    • When you want to redirect temporarily, but keep the original URL as the main one.

    • Example: A product page /product/123 is temporarily out of stock →

      GET /product/123
      → 302 Found → Location: /unavailable
      

⚖️ Key Difference

  • 301: Permanent → use when the resource has moved forever.
  • 302: Temporary → use when the move is just for a short time.

👉 Bonus: There are also 307 Temporary Redirect and 308 Permanent Redirect which are stricter versions of 302/301 (they preserve the HTTP method, e.g., POST stays POST).