Choosing 307 or 308 and finding redirect loops
Trace a POST through temporary and permanent redirects in a local HTTP fixture, then find the pair of rules that creates a trailing-slash loop.
How we checked this guide. We ran the loopback server and checked the request method and body received after each redirect with curl. We inspected the two sides of the slash loop separately. Editorial and testing standards
Choose the request that should reach the destination
Suppose a form sends a short draft to an endpoint that is moving from one path to another. Opening the old address in a browser tab only tests a GET. It tells you little about what happens to a POST carrying the draft. Before choosing a status, write down the request you expect the destination to receive. In this example the destination needs the same POST and its body. Only the path changes.
A 307 tells the client the move is temporary. A 308 describes a permanent move. Both preserve the method when the client automatically follows the redirect. The server can still receive clients that choose to stop and report the redirect. A different workflow applies when the first endpoint already accepted the draft and wants to show a receipt. A 303 can direct the user to retrieve that receipt. Sending another POST to the receipt page would ask it to handle an operation it was never designed to perform.
Start a local receiver that shows what arrived
Save the following as redirect-demo.mjs and run node redirect-demo.mjs with Node.js. It listens only on the loopback address. The receiver echoes the method and body of the request that reached it. The two redirect paths do no application work and send their visitors to the same receiver. This lets you follow a write-shaped request without writing a record, sending a message or relying on an external service.
Run the curl commands in another terminal while the fixture is running. The examples assume port 8127 is available. If it is occupied, choose an unused port in both the fixture and the commands. The redirect responses set Cache-Control to no-store so that a previously saved permanent mapping cannot influence repeated trials. The final echo is intentionally plain text. The receiver’s output makes the method and the marker visible even if the client usually presents only the final page.
import { createServer } from "node:http";
const routes = new Map([
["/temporary", [307, "/receive"]],
["/permanent", [308, "/receive"]],
["/catalog", [308, "/catalog/"]],
["/catalog/", [307, "/catalog"]],
]);
createServer(async (request, response) => {
const redirect = routes.get(request.url);
if (redirect) {
request.resume();
const [status, location] = redirect;
response.writeHead(status, { Location: location, "Cache-Control": "no-store" });
return response.end();
}
if (request.url !== "/receive") {
response.writeHead(404);
return response.end();
}
request.setEncoding("utf8");
let body = "";
for await (const chunk of request) body += chunk;
response.writeHead(200, { "Content-Type": "text/plain" });
response.end(request.method + " " + body + "\n");
}).listen(8127, "127.0.0.1");Follow the same POST through both statuses
The data option makes curl send a POST with a small form body. The location option follows redirects. Run the temporary case first and look for two independent pieces of evidence. The response headers should contain a 307 followed by a 200. The final text should be POST marker=blue. Then try the permanent case. The first status becomes 308, while the receiving method and the field name and value in the body stay unchanged.
A status list alone would miss a method change. A successful final response alone would miss a body change. Capturing both sides makes the test stronger. For a third comparison, run the temporary request without the data option. The receiver now prints GET and an empty body. That successful GET is exactly what opening the page from an address bar would demonstrate. It cannot stand in for the preceding form test.
curl --include --location --max-redirs 3 --data 'marker=blue' http://127.0.0.1:8127/temporary
curl --include --location --max-redirs 3 --data 'marker=blue' http://127.0.0.1:8127/permanent| Start | First response | Receiver output |
|---|---|---|
| POST /temporary | 307 | POST marker=blue |
| POST /permanent | 308 | POST marker=blue |
| GET /temporary | 307 | GET and an empty body |
Find the two rules that disagree about a slash
The catalog paths in the same fixture model a common deployment mistake. One layer adds the trailing slash and another removes it. Ask for each path once using the two commands below. Leaving automatic following off makes it easy to pair each requested path with the Location it returned. Resolve the first Location against the starting URL and then resolve the second. You end up at the original URL with the same method and no intervening change of state.
Changing one status from permanent to temporary would leave the two destinations identical. Instead choose the canonical spelling of the path. If the intended address is /catalog/, keep the redirect from /catalog and make /catalog/ serve the catalog itself. The expected trace from the short spelling is then a redirect followed by a successful content response. A request for the canonical spelling should go straight to the content. Check both entry points because one of them might already appear in bookmarks or internal links.
curl --silent --dump-header - --output /dev/null http://127.0.0.1:8127/catalog
curl --silent --dump-header - --output /dev/null http://127.0.0.1:8127/catalog/Trace a retry separately from a redirect
What if a real service records two drafts after a move? Start with a synthetic request identifier and look at the entries for both paths. In the fixture the original endpoint returns a redirect before doing any work, then the receiver handles the body once. Two logged requests are expected. Two stored drafts would indicate that both paths acted on the request or that a caller retried an operation after losing a response. These cases need different changes.
Use a copy of the workflow with a harmless receiver and send one submission. Record which path saw the identifier, which status each path returned and where the operation was applied. Then repeat as a distinct request with a new identifier. If duplicate handling is a concern, test the service’s documented retry or idempotency behavior independently. A method-preserving redirect by itself supplies no protection against a client submitting the same operation twice.
Check the method and the lifetime separately before release
The public Redirect Checker follows HTTP GET requests. It can show a sequence of destinations, an unexpected extra hop or a URL that repeats. Use it for public read paths once your change is available there. Use the local receiver, or an equivalent preview receiver you control, for method and body tests. A client that cannot replay a streamed body can report an error where curl can follow its small in-memory payload. Include the actual client in acceptance checks when its replay behavior matters.
A 308 can be reused by a cache under the HTTP caching rules, depending on the original method and cache controls. Decide what callers should do on their next visit as well as on this one. During a temporary deployment, leave a way to return to the original path. For a permanent move, update links and client configuration to send new traffic to the destination directly. Compare a fresh client with one that visited before the change. A discrepancy limited to the returning client warrants checking saved redirects before editing another server rule.