Skip to content

Field Notes

HTTP Redirect Chains: 301, 302, 307, and 308 Explained

Understand HTTP 301, 302, 307 and 308 redirects, method preservation, browser and CDN caching, redirect chains, loops and safe migration testing.

EmailLinkedIn
HTTP redirect-chain diagnosis pathRequestRedirect ownerStatus codeLocationCache behaviorFinal response
HTTP redirect-chain diagnosis path
Status Persistence Method behavior
301 Permanent May be rewritten by older clients
302 Temporary May be rewritten by older clients
307 Temporary Preserves method and body
308 Permanent Preserves method and body
On this page

Environment covered: Public HTTP applications behind CDN, reverse proxy, load balancer, NGINX, Apache, WordPress or framework routing layers

Choose a redirect status by answering two questions: is the move permanent, and must a following client preserve the request method? A page-navigation test answers neither question for an API write.

The distinction is easiest to see when the same migration rule handles both old article links and a submission endpoint.

The CMS migration and submission endpoint are fictional teaching examples. Request names and sample output are synthetic.

Permanence and method preservation

Separate permanence from method preservation. They are related operational choices, but they are not the same choice.

Status Meaning for the move What matters for a write request
301 Permanent Clients are permitted to change POST to GET in the familiar compatibility behavior.
302 Temporary POST-to-GET behavior is also permitted; do not depend on preservation.
307 Temporary A client that follows the redirect must preserve the method.
308 Permanent Method preservation combines with a long-lived migration decision.

If the desired behavior after a completed form submission is to show a separate result page with GET, 303 is the more explicit pattern to consider. That is a different design from transparently moving an API write to another endpoint.

The status alone does not guarantee that the client will follow. Authentication, cross-origin policy, client configuration and request replayability still matter. A streaming body may not be replayable, and a signature may cover the original URL.

Worked example: a migration that changes POST to GET

Imagine a Drupal application moving an old submission route behind a new public hostname. The migration redirects old URLs with 302 responses. Browsers navigating to pages arrive successfully, so the same rule is extended to the integration endpoint.

The integration sends a POST. Its redirect handling changes the next request to GET, and the destination no longer receives the original submission body. The route works as navigation but fails as a write interface.

The problem is not that 302 is inherently wrong. It is that the deployment never specified method behavior for that endpoint. Another client might refuse to follow the redirect entirely, or might follow it differently. A homepage check cannot settle that contract.

Observe the next request, not just the final URL

Start with one response, without following it. Check the exact scheme, hostname, path and query in Location.

curl -sS -o /dev/null -D - 'https://forms.example.test/old-submit'

For a disposable test endpoint that cannot create real work, compare the methods observed by the destination:

curl -sS -v -L --max-redirs 4 \
  --data 'probe=illustrative' \
  'https://forms.example.test/old-submit'

This is a synthetic-target example. Do not send test writes to a live business endpoint. Avoid adding -X POST casually to this diagnostic: forcing a custom method can change curl’s behavior and obscure what the ordinary client would do. Options such as --post301 and --post302 also alter the experiment rather than establish a universal default.

In a local harness, let the destination report the received method and body. The useful comparison is the initial request against the final request. A trace that stops at “followed redirect successfully” misses the fault entirely.

Method preservation does not make replay safe

Changing the illustrative route to 307 removes the method-change ambiguity, but it does not make replay safe. If an upstream timed out after committing work, a retry or redirected replay may create a duplicate submission.

Use an idempotency key or another application-specific transaction boundary for operations that must happen once. Test how long the key remains valid and what happens when the same key carries different data. Redirects cannot provide that guarantee.

Also inspect credentials and signatures. A destination on another host may not receive the same authorization headers, and it should not automatically receive sensitive credentials just because it appears in Location. Signed webhook and callback URLs may need a sender-side configuration update instead of a redirect.

Browser cache, edge cache and origin state can disagree

Once a permanent redirect reaches a client, reversing the server rule may not reverse that client’s behavior immediately. An edge invalidation can remove the CDN’s object, but it cannot clear a browser’s remembered response.

Temporary redirects are often useful during a migration, with explicit cache directives and a cache policy that respects them. “Temporary” should not be confused with “incapable of being cached.” Inspect the actual response headers and the configured intermediary behavior.

Query parameters need a deliberate policy as well. Search terms, callback state and signed values are not disposable campaign decoration. A redirect that preserves the path while dropping a required query can produce a completely different failure from the missing POST body.

Reduce the chain rather than adding a clever last hop

An old path can bounce through HTTP-to-HTTPS, apex-to-www, slash normalization and an application canonical rule before reaching its destination. Each rule may be understandable; the accumulated chain may still be unnecessary.

Assign an owner to each transformation. Then test whether supported old entry points can reach the canonical destination with fewer transitions. Update internal links and sitemaps to point directly to the final URL instead of keeping the old chain alive indefinitely.

TLS is part of this sequence before HTTP begins. A certificate must cover the hostname a client first contacts; a redirect from that host cannot repair a certificate warning that prevents the connection from completing.

Select the status for the endpoint contract

For content navigation, a proven 301 may be appropriate. For a stable write interface that genuinely needs method-preserving redirection, 308 may fit. For an endpoint controlled by a known integration, changing the sender’s configured destination may be clearer than relying on redirect support at all.

Before making that choice, test the actual client families, methods, bodies, query handling, authentication and rollback behavior. Include error paths as well as the happy path. Keep the expected status and destination beside the routing configuration so future changes have something concrete to contradict.

Document the expected method and destination alongside the rule. A future migration test should fail if a POST becomes GET, required query state disappears or a redirect sends credentials beyond the intended trust boundary. A final 200 cannot detect those regressions.

Sources and further investigation

References support the protocol and product behavior discussed here; they are not evidence that the illustrative scenario occurred.

Continue the investigation

Need a second set of eyes?

Working through a similar production issue?

Discuss the technical context