jboesch
jboesch

Reputation: 13

help with mod-rewrite for REST API (kind of like the twitter API)

I've got a question for the mod-rewrite gurus out there :p

I've got a REST api built, I'm just working on the .htaccess mod-rewriting for some nice URLs.

I would like this... api.site.com/[contacts].[json]?location=[new york,NY]

To map to this... site.com/includes/api/v2/api_receiver.php?action=[contacts]&format=[json]&location=[new york,NY]

The parameters are in square brackets.

It's basically like the twitter API: http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-POST-lists

Any help is much appreciated :)

Upvotes: 1

Views: 1630

Answers (2)

Casey Chow
Casey Chow

Reputation: 1814

As for the domain redirection, you'll need

ServerAlias api.site.com site.com

(Thanks for making me learn mod_rewrite, by the way)

Upvotes: 0

Brent C
Brent C

Reputation: 111

This should do it:

RewriteRule ^([a-z0-9]+)\.([a-z0-9]+)$    /includes/api/v2/api_receiver.php?action=$1&format=$2 [L,QSA,NC]

QSA = Query-String-Appened, which will take care of appending the location=... part to the end.

NC = nocase, which will lets a-z match A-Z too.

Upvotes: 2

Related Questions