A form submits a POST to /login, the server answers with a 301 redirect, and the login silently fails. The client followed the redirect, but it switched to GET on the way and dropped the form data. The HTTP specification allows exactly that for 301 and 302, “for historical reasons,” and most clients do it. A small local test server, the Python requests library and curl make the behavior easy to see, including one curl combination that sends a POST with an empty body, which is arguably worse than either choice.
The five redirect codes
What RFC 9110 says
RFC 9110, the June 2022 standard that defines HTTP’s semantics, covers the redirect codes in section 15.4. The key lines:
| Code | Name | Permanent? | Method on redirect |
|---|---|---|---|
| 301 | Moved Permanently | yes | a user agent may change POST to GET “for historical reasons” |
| 302 | Found | no | same allowance: POST may become GET |
| 303 | See Other | no | used to send a client from a POST’s result to another resource, fetched with GET |
| 307 | Temporary Redirect | no | the user agent must not change the request method |
| 308 | Permanent Redirect | yes | like 301, but the method may not change |
Caching
The RFC also says 301 and 308 responses are heuristically cacheable, meaning a browser may remember them and skip asking the old URL next time even without explicit cache headers. A permanent redirect set by mistake can therefore stick in visitors’ browsers after the server is fixed. The 302 and 307 sections carry no such statement.

The test setup
A local server that reports what it received
The test server, about a dozen lines of Python’s http.server, answered any request to /r/<code> with that status code and a Location: /target header. A request to /target returned the method it received and the body that came with it:
class H(BaseHTTPRequestHandler):
def handle_any(self):
n = int(self.headers.get('Content-Length') or 0)
body = self.rfile.read(n) if n else b''
if self.path.startswith('/r/'):
code = int(self.path.split('/')[2])
self.send_response(code)
self.send_header('Location', '/target')
self.send_header('Content-Length', '0')
self.end_headers()
return
msg = f"{self.command} {self.path} body={body.decode()!r}".encode()
...
do_GET = do_POST = do_PUT = do_HEAD = handle_anyEach client sent a POST with the form body x=1 to each redirect code.
What Python requests does
The results
Using requests 2.34.2 on Python 3.13:
| Redirect | What arrived at /target |
|---|---|
| 301 | GET /target, empty body |
| 302 | GET /target, empty body |
| 303 | GET /target, empty body |
| 307 | POST /target, body x=1 |
| 308 | POST /target, body x=1 |
Reading them
Requests takes the RFC’s historical allowance for 301 and 302 and switches to GET, follows 303 as designed, and preserves both method and body for 307 and 308. The library’s quickstart guide says it performs location redirection for all verbs except HEAD by default, and the test confirmed it: a HEAD request to the 308 URL came back as a bare 308 with an empty history. Every followed redirect shows up in Response.history, the place to look when a request seems to land somewhere unexpected. Passing allow_redirects=False returns the redirect itself, so a script can inspect the Location header before deciding what to do.

What curl does, and the empty POST
Two ways to send a POST
curl 8.5.0 was run two ways: with -d 'x=1' -L, which makes curl choose POST because data is present, and with -X POST -d 'x=1' -L, which forces the method name.
| Redirect | curl -L -d |
curl -L -X POST -d |
|---|---|---|
| 301 | GET, empty body | POST, empty body |
| 302 | GET, empty body | POST, empty body |
| 303 | GET, empty body | POST, empty body |
| 307 | POST, body x=1 |
POST, body x=1 |
| 308 | POST, body x=1 |
POST, body x=1 |
The trap
The middle column is what most people intend. The right column is a common copy-and-paste habit, and on 301, 302 and 303 it produces a POST with no body, a request the server may treat as a malformed submission rather than either the original POST or a clean GET. The curl manual explains why: with the location option, the method set by --request is used in all subsequent requests regardless of response code, while a newer --follow option uses the custom method only for 307 and 308 and may reset it to GET for 301, 302 and 303. The practical advice is to drop -X POST when sending data with -d, since -d already implies POST.
Chains and loops
Two more tests
A second test server added two more cases: a pair of URLs that redirect to each other forever, and a chain of 301 redirects where each hop waits 50 milliseconds before answering, roughly what a slow upstream might add.
| Test | Result |
|---|---|
| Python requests, redirect loop | stopped with TooManyRedirects: Exceeded 30 redirects. |
| curl -L, redirect loop | gave up after 50 redirects, exit code 47 |
| 1 redirect hop at 50 ms each | 53 ms total |
| 2 hops | 105 ms |
| 4 hops | 211 ms |
| 6 hops | 313 ms |
Requests sessions carry a max_redirects attribute set to 30 by default, and curl stopped at 50, so a loop doesn’t hang either client forever, but it does burn dozens of round trips before failing. Chains cost time in a straight line: every hop is a full request and response. A site that redirects http://example.com to https://example.com to https://www.example.com to https://www.example.com/ makes every first-time visitor pay three extra round trips. Collapsing a chain into a single redirect straight to the final URL is one of the cheapest speed fixes available, and on a home lab reverse proxy it usually means one return line instead of three.
A script that prints every hop
Browsers hide the chain. A dozen lines of Python show it, one request at a time, with redirects turned off so each hop is visible:
import sys, requests
from urllib.parse import urljoin
def trace(url, limit=10):
for _ in range(limit):
r = requests.get(url, allow_redirects=False, timeout=5, stream=True)
print(r.status_code, url)
if r.status_code not in (301, 302, 303, 307, 308):
return
url = urljoin(url, r.headers["Location"])
print("stopped after", limit, "hops")
trace(sys.argv[1])Against the test server’s three-hop chain it printed three 301 lines and a final 200 for /done. Against the loop it alternated between /loop and /loop2 and printed “stopped after 10 hops.” The urljoin call matters: Location headers are often relative, like the /target used in these tests, and have to be resolved against the current URL. Using stream=True avoids downloading a large body at each step.

What it means for SEO
Permanent versus temporary to Google
Google Search Central’s redirect documentation says Google uses 301 and 308 as a signal that the redirect target should be canonical, while 302, 303 and 307 are not used as that signal, so the source URL tends to stay in results. It also treats an instant meta refresh as permanent and a delayed one as temporary, and advises using permanent redirects when the change won’t be reverted.
Choosing a code
| Situation | Code |
|---|---|
| Page or site moved for good, GET traffic | 301 or 308 |
| Moved for good, and POST or PUT must keep working | 308 |
| Temporary move, such as a maintenance page | 302 or 307 |
| After a form POST, show a result page | 303 |
| HTTP to HTTPS for a whole site | 301, or 308 if APIs accept POST on the old URL |
Setting them in nginx
The return directive
nginx’s rewrite module documentation gives the syntax return code URL; and says a redirect URL can be given for codes 301, 302, 303, 307 and 308. A typical HTTP-to-HTTPS server block for a home lab:
server {
listen 80;
server_name example.home.arpa;
return 308 https://$host$request_uri;
}
Version notes worth knowing
The same page notes that nginx did not treat 307 as a redirect until versions 1.1.16 and 1.0.13, and did not treat 308 as one until 1.13.0. Any current distribution package is far newer, but an old embedded device or appliance running an ancient nginx may not. The page also documents the older rewrite flags: redirect returns a 302 and permanent returns a 301.
Testing a redirect before trusting it
curl -sI http://example.home.arpa/ shows the status line and Location header without following anything. Checking that first avoids the cached-301 problem: a browser that has already seen a wrong permanent redirect may keep following it until its cache is cleared, while curl always asks fresh.
Sources
- IETF, RFC 9110, “HTTP Semantics” (June 2022): https://www.rfc-editor.org/rfc/rfc9110.html
- Requests documentation, “Quickstart”: https://requests.readthedocs.io/en/latest/user/quickstart/
- curl, “curl man page”: https://curl.se/docs/manpage.html
- Google Search Central, “Redirects and Google Search”: https://developers.google.com/search/docs/crawling-indexing/301-redirects
- nginx documentation, “Module ngx_http_rewrite_module”: https://nginx.org/en/docs/http/ngx_http_rewrite_module.html
