nginx rewrite post data

前端 未结 3 1240
时光说笑
时光说笑 2020-12-18 02:34

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

3条回答
  •  萌比男神i
    2020-12-18 02:46

    You just need to write a Nginx rewrite rule with HTTP status code 307 or 308:

    location  ~ user_info.php {
      return 307 http://testing.com/userhistory;
    }
    

    Http Status code 307 or 308 should be used instead of 301 because it changes the request method from POST to GET. Refer https://tools.ietf.org/id/draft-reschke-http-status-308-07.html#introduction

    Also redirecting via return is better compared to rewrite according to nginx doc: https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#taxing-rewrites

提交回复
热议问题