【发布时间】:2012-01-28 03:58:03
【问题描述】:
我希望每次通话都与
http://localhost/api/
(作为根文件夹)例如http://localhost/api/get/users实际上是http://localhost/api/index.php?handler=get/users。
http://localhost/api/get/user/87 应该是 http://localhost/api/index.php?handler=get/user/87 在 index.php 中我会捕获 $_GET 变量 handler 并以适当的方式处理它。
如果我有这种重写规则,它只适用于一个
RewriteRule ^([^/\.]+)/?$ index.php?handler=$1 [QSA,L]
两个
RewriteRule ^([^/\.]+)/?$ index.php?handler=$1 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?handler=$1&handler2=$2 [QSA,L]
三个斜线等等...
RewriteRule ^([^/\.]+)/?$ index.php?handler=$1 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?handler=$1&handler2=$2 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?handler=$1&handler2=$2&handler3=$3 [QSA,L]
所以对于第一种情况,http://localhost/api/a 可以工作,但http://localhost/api/a/b 会导致 Not Found 错误。
编辑:这样可以吗?
RewriteRule ^(.*)$ index.php?handler=$1 [L,QSA]
【问题讨论】:
标签: php api rest mod-rewrite