Using mod_rewrite for a RESTful api

Posted by razass on Server Fault See other posts from Server Fault or by razass
Published on 2010-03-25T03:17:06Z Indexed on 2010/03/25 3:23 UTC
Read the original article Hit count: 775

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/index.php" and 'houses', '123', 'abc' need to be able to be parsed out of the URL in that index.php. It also can't alter the http headers or body.

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

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

<IfModule mod_rewrite.c>
    RewriteEngine on
        RewriteCond $0 !^webroot/
        RewriteRule .* webroot/$0 [L]
</IfModule>

Which appears to be working but I am not sure if it is correct.

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

Thanks in advance!

© Server Fault or respective owner

Related posts about mod-rewrite

Related posts about php