How to configure Apache so that PHP processes OPTIONS HTTP requests?

To set up the correct test suite for CORS (cross-domain requests), I need to be able to process the HTTP OPTIONS method directly from the script. Therefore, I have a simple PHP script that defines the OPTIONS method and reacts accordingly by outputting some specific headers.

The PHP side is not a problem. If I use curl to give out GET / POST / HEAD / PUT / etc. they all turn to the script, and it handles them clearly. However, if I issue an OPTIONS request, it never reaches the script: Apache immediately responds to a list of a set of methods that, in its opinion, are suitable for this resource. I can say that the script does not run (no registration, none of its output files respond to it, etc.).

I look through the Apache configuration, make sure that the appropriate .htaccess is not suitable, I changed a bunch of things like the Limit / LimitExcept directives, but I can not get it to change its behavior. I also tried to find technology information from my youth that could help here: NPH scripts (untreated headers); but apparently this has disappeared (at least I cannot find any information about this that works).

So the question is this: how do I configure Apache to allow my script to describe OPTIONS?

+6
source share
1 answer

I just tested my own PHP (5.3, Apache 2.2) and it still works (as it was for a while). OPTIONS are passed and appear in the $ _SERVER array, as you would expect

The goal should be to return the default settings (which should work) and then back up the conf with the other options you need.

Otherwise, without seeing the .conf file, we flew blind - these are some things to look for.

  • Limit directives. You said that you checked there, but just for debugging, remove all links. Include any of the vhosts, and you can also change individual directories.
  • Same thing for LimitExcept (you said you tried it - just delete them all)
  • Check both .conf and .htaccess for any redirects or other conditions based on RequestHeader or RequestHeader (do a search and analysis)
  • [I also read something about the THE_REQUEST check, but have never heard of it before. Worth checking out too?]
  • Finally, make sure you do not have a special handler specified for OPTIONS, i.e. Script OPTIONS /cgi-bin/optionshandler , and that your PHP handler is also specified to handle only GET and POST. Remember again that vhosts and directories and .htaccess can be individually changed, so check all of them.

That’s all I can think of. Otherwise, as I suggested, start from scratch (it works) and do the rest until it works.

+3
source

All Articles