帮助 REST API 进行 mod-rewrite(有点像 twitter API)

发布于 2024-09-13 04:17:24 字数 529 浏览 3 评论 0原文

我有一个问题要问 mod-rewrite 专家:p

我已经构建了一个 REST api,我正在为一些不错的 URL 进行 .htaccess mod-rewriting。

我想要这个... api.site.com/[contacts].[json]?location=[new york,NY]

要映射到此... site.com/includes/api/v2/api_receiver.php?action=[contacts]&format=[json]&location=[new york,NY]

参数位于方括号中。

它基本上就像 twitter API: http://apiwiki.twitter .com/Twitter-REST-API-Method%3A-POST-lists

非常感谢任何帮助:)

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情深已缘浅 2024-09-20 04:17:24

这应该可以做到:

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

QSA = Query-String-Appened,它将负责将 location=... 部分附加到末尾。

NC = nocase,这将使 az 也匹配 AZ。

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.

蓬勃野心 2024-09-20 04:17:24

至于域名重定向,你需要

ServerAlias api.site.com site.com

(谢谢你让我学习 mod_rewrite,顺便说一句)

As for the domain redirection, you'll need

ServerAlias api.site.com site.com

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文