URL带参数的重定向

wpfly2020 2014-05-02 07:17:22
要将下面类型的地址重定向

api/123/ -> api/index.php?c=123
api/abc/ -> api/index.php?c=abc
api/abc/?p=1 -> api/index.php?c=abc&p=1

api/下的其他任何路径不定向。

RewriteEngine on
RewriteRule ^api/(.*)/\?(.*)$ api/index.php?c=$1&$2
RewriteRule ^api/(.*)/$ api/index.php?c=$1

这个貌似不行,

对于api/abc/?p=1

c能$_GET到值,p就不行了
...全文
344 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
傲雪星枫 2014-05-05
  • 打赏
  • 举报
回复
引用 楼主 feiniaoflyer 的回复:
要将下面类型的地址重定向 api/123/ -> api/index.php?c=123 api/abc/ -> api/index.php?c=abc api/abc/?p=1 -> api/index.php?c=abc&p=1 api/下的其他任何路径不定向。 RewriteEngine on RewriteRule ^api/(.*)/\?(.*)$ api/index.php?c=$1&$2 RewriteRule ^api/(.*)/$ api/index.php?c=$1 这个貌似不行, 对于api/abc/?p=1 c能$_GET到值,p就不行了
这样就可以了。 <IfModule mod_rewrite.c> RewriteEngine On RewriteRule ^api/(.*)/$ api/index.php?c=$1 [QSA,L] RewriteRule ^api/(.*)/(.*)$ api/index.php?c=$1%{QUERY_STRING} [L] </IfModule>
PhpEr_贵 2014-05-04
  • 打赏
  • 举报
回复
不知道你最后是怎么解决的 求告知
  • 打赏
  • 举报
回复
RewriteRule ^api/(.*)/\?(.*)$ api/index.php?c=$1&$2 [QSA,L] 加上 [QSA,L]看看行不?
黄袍披身 2014-05-02
  • 打赏
  • 举报
回复
api/123/ api/abc/ 这两个直接匹配嘛 这样其他路径就不会匹配了 才符合你的要求...

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧