Nginx Redirect POST Request Data Loss Issue
·
1 min read
Created two websites, Website A and Website B. Website A receives POST submissions and then redirects to Website B. The redirection is configured in Nginx. For specific configuration syntax, please refer to the official Nginx documentation. Here I’ll only show the key statements.
Original Configuration
# rewrite ^.+ http://b.com$uri;
However, after testing, we discovered an issue: when redirecting to B, the form submission data would be lost.
Solution
After researching, we found that rewrite
indeed causes POST data loss. Therefore, we should use 307
redirection. The specific configuration is as follows:
return 307 $scheme://b.com$request_uri;
Explanation
HTTP Status Code 307 Meaning
HTTP-307 is a temporary redirect, indicating that the request has been temporarily moved to the given target address. Both the method and request body will be reused for the redirected request.