How to configure Apache to let PHP handle OPTIONS HTTP requests?
Posted
by
Robin Berjon
on Server Fault
See other posts from Server Fault
or by Robin Berjon
Published on 2012-11-27T09:30:38Z
Indexed on
2012/11/28
5:07 UTC
Read the original article
Hit count: 505
In order to set up a proper test suite for CORS (cross-domain requests) I need to be able to handle the HTTP OPTIONS method directly from script. I therefore have a simple PHP script that detects the OPTIONS method, and reacts accordingly by outputting some specific headers.
The PHP side is not a problem. If I use curl to issue GET/POST/HEAD/PUT/etc. requests they all go to the script and it clearly handles them fine. If I issue an OPTIONS request however, it never reaches the script: Apache immediately replies listing a set of methods that it believes to be appropriate for this resource. I can tell that the script isn't run (no logging, none of its output makes it to the response, etc.).
I've been going through the Apache configuration, have made sure no applicable .htaccess is in the way, I've tweaked a bunch of things such as Limit/LimitExcept directives, but I can't get it to change its behaviour. I've also tried to find information on a technique from my youth that could have helped here: NPH (non-parsed headers) scripts; but apparently that has now disappeared (at least, I can't find any recent information about it that works).
So the question is: how do I tweak Apache's configuration so that it will let my script handle OPTIONS?
© Server Fault or respective owner