我需要将 POST 数据保存到不同的 url
重写有效,但发布数据丢失
需要将数据从 user_info.php 发布到 userhistory
location ~ user_info.php {
rewrite ^/.* http://testing.com/userhistory permanent;
}
数据丢失。如何保存数据?
最佳答案
你只需要写一个带有 HTTP 状态码的 Nginx 重写规则 307
或 308
:
location ~ user_info.php {
return 307 http://testing.com/userhistory;
}
Http 状态码
307
或 308
应该用来代替 301
因为它将请求方法从 POST 更改为 GET。引用https://tools.ietf.org/id/draft-reschke-http-status-308-07.html#introduction
还通过
return
重定向与 rewrite
相比更好根据 nginx 文档:https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#taxing-rewrites
关于nginx 重写帖子数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27795068/