duandeng7132 2014-06-14 11:18
浏览 18
已采纳

与mod_rewrite合并的参数

I'm currently using the following line to convert /pages/group/index.php?id=1&slug=example-name into group/1-example-name which works perfectly and I can retrieve the ID and slug using $_GET but when I try to add an additional parameter for the page number, I cannot retrieve the page number and it becomes part of the slug.

Two parameters

RewriteRule ^group/([^-]*)-([^.]*)$ /pages/group/index.php?id=$1&slug=$2 [L]

Additional third parameter

RewriteRule ^group/([^-]*)-([^.]*)/([0-9]+)$ /pages/group/index.php?id=$1&slug=$2&page=$3 [L]

So if the ID parameter is 1, the slug parameter is hello-example and the page parameter is 10 - the ID will return perfectly but the slug will return as hello-example/10 and the page number will return as empty.

Any help would be much appreciated :)!

  • 写回答

1条回答 默认 最新

  • dousi1970 2014-06-14 14:04
    关注

    As already pointed out in the comments, the string "some-title/pagenumber" is matched by the first rewriterule. It will therefore never be matched by the second rewriterule. In this case you just want the rules to be matched in the opposite order, so just switch the order of the rules:

    RewriteRule ^group/([^-]*)-([^.]*)/([0-9]+)$ /pages/group/index.php?id=$1&slug=$2&page=$3 [L]
    RewriteRule ^group/([^-]*)-([^.]*)$ /pages/group/index.php?id=$1&slug=$2 [L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?