I need to preserve the POST data to a different url
The rewrite works but the post data is lost
need to post data from user_info.php to userhistory
location ~ user_info.php {
rewrite ^/.* http://testing.com/userhistory permanent;
}
The data is lost. How can I preserve the data?
In my conf I use try_files with regex
for example
Basically, you want to automatically redirect a POST request using a 301 Moved Permanently redirect.
However. such redirect are specifically disallowed by the HTTP Specifications which states that:
The specs also note that:
I believe the second situation may be what is going on and that while the target server is expecting POST data, it is receiving GET data instead.
Your choices are:
A. Change the code to work with GET data or better still, both POST and GET. I.E., look for POST and if not there, try GET equivalents.
B. Try to ensure the code receives POST data by working with the Spec.
You may be able to achieve Choice B by using the proxy_pass directive to handle the request instead.
Something such as:
In this way, the user is technically not being redirected.
You just need to write a Nginx rewrite rule with HTTP status code
307
or308
:Http Status code
307
or308
should be used instead of301
because it changes the request method from POST to GET. Refer https://tools.ietf.org/id/draft-reschke-http-status-308-07.html#introductionAlso redirecting via
return
is better compared torewrite
according to nginx doc: https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#taxing-rewrites