Using mod_rewrite for a RESTful api

Posted by razass on Stack Overflow See other posts from Stack Overflow or by razass
Published on 2010-03-24T05:28:53Z Indexed on 2010/03/24 5:33 UTC
Read the original article Hit count: 500

Filed under:

Say the user is making a request to the following url:

"http://api.example.com/houses/123/abc"

That request needs to map to "/webroot/controls/houses.php" and send "123" and "abc" to houses.php as variables without modifying the http headers or body.

"houses" could theoretically be anything; cars, boats; and map to the corresponding php file... cars.php, boats.php respectively with a fallback to index.php if there is no match.

There can be any number of variables after "houses" ie) "http://api.example.com/houses/1234/abc/zxy/987"

I think I already have ALL requests being sent to webroot using:

<IfModule mod_reqrite.c>
    RewriteEngine on
    RewriteRule ^$  webroot/    [L]
    RewriteRule (.*)    webroot/$1  [L]
</IfModule>

But now I am at a loss as to how to take the next step as mentioned above.

Any help is appreciated, even if you feel that I am taking the wrong approach.

Thanks in advance!

© Stack Overflow or respective owner

Related posts about mod-rewrite