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
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