Search code examples
apacheresthttp-verbs

POST Requests seen as GET by server


Got a really strange problem here. When sending post requests to my PHP script

$_SERVER['REQUEST_METHOD'] 

returns "GET" instead of "POST".

It works fine for every other REST method

so this is what I get

GET -> GET
POST-> GET
PUT -> PUT
DELETE -> DELETE

It only happens on one of my servers so i'm assuming it's an apache problem and i've managed to figure out that it only happens if I add "www" to my url.

I.e

www.something.com

causes the problem but

something.com

does not

I have tested on different sites on the same server and I get the same thing so I'm assuming it's global config.

Any thoughts


Solution

  • As the HTTP spec says for response codes 301 and 302:

    Note: For historic reasons, a user agent MAY change the request method from POST to GET for the subsequent request. If this behavior is undesired, the 307 (Temporary Redirect) status code can be used instead

    A third (but unlikely) possibility is you're getting a 303 response to the initial URI. The solution is twofold:

    • Configure the clients which are under your control to POST to the canonical URI so they are not redirected at all.
    • Configure your server to redirect using 307 in this case instead of 301/302.