开发者

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

开发者 https://www.devze.com 2023-01-11 02:37 出处:网络
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'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 :)


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.


As for the domain redirection, you'll need

ServerAlias api.site.com site.com

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

0

精彩评论

暂无评论...
验证码 换一张
取 消