views:

108

answers:

1

I would like to arrange things so that a GET request for e.g.

http://example.com/user/[email protected]

internally calls the script

/var/www/example.com/rest/user/GET.php

and a PUT request for the same URL internally calls the script

/var/www/example.com/rest/user/PUT.php

and so on for the other HTTP verbs POST and DELETE.

It's almost possible to achieve this via the <Script> directive, but it doesn't quite work, because "Script with a method of GET will only be called if there are query arguments present". This means that if Apache is configured via

<Location /user>
Script GET /rest/user/GET.php
Script PUT /rest/user/PUT.php
</Location>

then, whilst a GET request for

http://example.com/user/[email protected]?foo=bar

will call GET.php, if the request does not contain the query string "foo=bar", it doesn't.

(Also, why was <Script> designed like this in the first place?)

+2  A: 

You could use mod_rewrite making use of a RewriteCond on REQUEST_METHOD

e.g.:

RewriteCond %{HTTP_METHOD} ^GET$
mopoke
I actually tried a mod_rewrite solution first, but that failed for other reasons (something went wrong in ScriptAlias and/or the FastCGI-powered PHP) that seemed more difficult to solve... If you do have this working, can you post your Apache conf?
mjs