PHP Redirect with POST data

后端 未结 13 1457
不思量自难忘°
不思量自难忘° 2020-11-22 06:22

I did some research on this topic, and there are some experts who have said that it is not possible, so I would like to ask for an alternative solution.

My situation

13条回答
  •  终归单人心
    2020-11-22 07:15

    I'm aware the question is php oriented, but the best way to redirect a POST request is probably using .htaccess, ie:

    RewriteEngine on
    RewriteCond %{REQUEST_URI} string_to_match_in_url
    RewriteCond %{REQUEST_METHOD} POST
    RewriteRule ^(.*)$ https://domain.tld/$1 [L,R=307]
    

    Explanation:

    By default, if you want to redirect request with POST data, browser redirects it via GET with 302 redirect. This also drops all the POST data associated with the request. Browser does this as a precaution to prevent any unintentional re-submitting of POST transaction.

    But what if you want to redirect anyway POST request with it’s data? In HTTP 1.1, there is a status code for this. Status code 307 indicates that the request should be repeated with the same HTTP method and data. So your POST request will be repeated along with it’s data if you use this status code.

    SRC

提交回复
热议问题