views:

43

answers:

2

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 :)

A: 

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.

Brent C
Oh, I missed the domain change... Good catch Casey C.
Brent C
A: 

As for the domain redirection, you'll need

ServerAlias api.site.com site.com

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

digitxp