This is in one of my vhost config files. What I'm trying to do with the lines delimited with #********** is make the Apache server itself handle an OPTIONS request, rather than forwarding it to the back end (a Mongrel cluster, using mod_proxy_balancer).
It works OK if I use the "main" server name for my apache:
#################################
$ telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
OPTIONS / HTTP/1.0
Host:localhost
HTTP/1.1 200 OK
Date: Thu, 02 Nov 2006 17:36:50 GMT
Server: Apache
Allow: GET,HEAD,POST,OPTIONS,TRACE
Content-Length: 0
Connection: close
Content-Type: text/html
Connection closed by foreign host.
#################################
It doesn't work if I use my vhost (using the config fragment below):
#################################
telnet localhost 80
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
OPTIONS / HTTP/1.0
Host:my-vhost-hostname
HTTP/1.1 400 Bad Request
Date: Thu, 02 Nov 2006 17:36:23 GMT
Server: Apache
Vary: Accept-Encoding
Content-Length: 308
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache Server at my-vhost-hostname Port 80</address>
</body></html>
Connection closed by foreign host.
#################################
Config file:
RewriteEngine On
# balancer-manager doesn't forward to the cluster
RewriteRule ^/balancer-manager.* - [PT,L]
#**********
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^/(.*)$ $1 [PT,L]
#**********
# If there is a maintenence.html file in your
# public dir all requests will get rerouted to
# this file. This is for use with capistrano
RewriteCond %{DOCUMENT_ROOT}/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /maintenance.html [L]
# Rewrite index to check for static index.html
RewriteRule ^/$ /index.html [QSA]
# Rewrite to check for Rails cached pages with .html extentions
RewriteRule ^([^.]+)$ $1.html [QSA]
# All dynamic requests get sent to the cluster
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://staging%{REQUEST_URI} [P,QSA,L]
# Deflate for clients that support it.
AddOutputFilterByType DEFLATE text/html text/plain text/xml
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html