I am trying to write a little rest api in php using mod_rewrite.
My question is: How to handle HTTP DELETE and PUT? For example, the URL would be: / Book / 1234
where 1234 is the unique identifier of the book. I want to "redirect" this identifier (1234) to book.php with the id parameter. I already know how to read PUT and DELETE variables in php script, but how to set these rewrite rules in mod_rewrite?
Any ideas?
Edit: The rewrite rule for GET will look like this:
RewriteRule book/([0-9]+) book.php?id=$1 [QSA]
How do I do this "parameter transfer" for PUT and DELETE? As far as I know, HTTP POST, PUT and DELETE use the body of an HTTP request to pass parameter values. Therefore, I think I need to add this parameter to the body of the HTTP request. But I do not know how to do this with mod_rewrite.
Is there any way to mix DELETE and GET?
RewriteCond %{REQUEST_METHOD} =DELETE
RewriteRule book/([0-9]+) book.php?id=$1 [QSA]
Then in book.php I would request the book identifier $ _GET ['id'], even if the HTTP HEADER says that the HTTP method is DELETE. It doesn't seem to work ...
source
share