R
R
Roman Rakzin2020-05-07 14:27:00
htaccess
Roman Rakzin, 2020-05-07 14:27:00

Why are requests from the POST method redirected to GET?

Site on wordpress.
I added api to htaccess:

RewriteCond %{REQUEST_URI} ^/api/ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ api/api.php [QSA,L]

when I try to POST a request, I first see a 301 redirect in the browser and then reload at the same GET request address.
Although in Postman, when testing the POST method, the server responds. How can I get the POST response in the browser using the POST method?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Rakzin, 2020-05-10
@TwoRS

It turns out that Apache, when making a POST request to a folder URL without a trailing slash, redirects to a URL with a slash, and the request is transformed into a GET. If you put a slash, then the effect disappears.
Conclusion: In the action of the form, always put a slash at the end of the folder URL, or better, use the file URL.
It turns out such a scheme
1. We send a POST to mysite/mydir
2. The server answers us with 301 to mysite/mydir/ (why this is correct is described in the Apache documentation)
3. The browser makes a GET without parameters to mysite/mydir/ (that's right to do, this is described in RFC 2616)
As a result, instead of our POST with parameters, we get a GET without parameters. Everything is logical, but somewhat unexpected.

I
Ilya, 2020-05-07
@New_Horizons

https://developer.mozilla.org/ru/docs/Web/HTTP/Sta...
As far as I understand, the browser hammers a bolt on saving the request method with 301 redirects. Need 308.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question