Answer the question
In order to leave comments, you need to log in
How to redirect a POST request from a PHP file to the Yii2 framework controller using htaccess so that the Body is not lost?
Requests coming to mysite.com/mysqlsave.php
must be redirected using .htaccess to the Yii2 framework controller, and specifically
mysite.com/frontend/web/api/save.
In this case, the request is sent using the POST method and contains JSON data and an authorization token , it is necessary that they are not lost during a redirect.
I tried this: Redirect 301 /mysqlsave.php /frontend/web/api/save - JSON data is lost
Answer the question
In order to leave comments, you need to log in
This is a very strange approach.
Apparently this is done on purpose to make life more interesting for those who support your code)
In general, if the POST request comes to this address: mysite.com/mysqlsave.php
Then you can simply add the rule 'mysqlsave.php' => 'frontend/web/api' to the url ruler /save' and delete mysqlsave.php.
Then all requests will go immediately to the right place, without any redirect.
A redirect can't check this
Ivankomolin, thanks for the answer.
However, you can also use a redirect, I will answer the question myself, because I found a working solution while waiting for a response from the community:
RewriteRule mysqlsave.php /frontend/web/api/save [NC,P]
With such a redirect, the request body was not lost.
And all this was necessary for the fact that there are firmware devices that send requests to this address and in order not to change all the firmware in old devices, it is easier to do redirection.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question