apache mod_rewrite 正则表达式多参数问题
正则表达式一直是我的烦恼。每当我以为我终于得到它时,我就会遇到一个新问题!
我想捕获这样的网址:
http://www.mydomain.com/boutique/blabla-1/bla-bla2/99/104
http://www.mydomain.com/boutique/blabla1/99
最终:
http://www.mydomain.com/boutique/blabla-1/bla-bla2/product1/99/104/55/
经过多次尝试和错误,我想出了这个,它似乎适用于 http://www.gskinner.com/RegExr/ 但不在 apache 中
^.*/boutique/([a-zA-Z-]*)(/?[a-zA-Z-]*)/?([0-9]*)/?([0-9]*)/?$ boutique.php?c1=$3&c2=$4
(到目前为止我只使用前两个 url)
我的 apache 重写日志调试文件是无助的:
通过/Users/iko/Sites/mysite/boutique.php
我只对获取 ids 感兴趣。任何帮助我们都会受到欢迎!
谢谢。
Regular expressions have always been my pet peeves. Every time I think that I finally got it I have a new problem !
I want to catch url like this :
http://www.mydomain.com/boutique/blabla-1/bla-bla2/99/104
http://www.mydomain.com/boutique/blabla1/99
and eventually :
http://www.mydomain.com/boutique/blabla-1/bla-bla2/product1/99/104/55/
after a lot of tries and errors I came up with this which seems to work with http://www.gskinner.com/RegExr/ but not in apache
^.*/boutique/([a-zA-Z-]*)(/?[a-zA-Z-]*)/?([0-9]*)/?([0-9]*)/?$ boutique.php?c1=$3&c2=$4
(I was only working with the first two url so far)
MY apache rewrite log debug files are helpless :
pass through /Users/iko/Sites/mysite/boutique.php
I'm only interrested in getting the ids. Any help we'll be welcomed !
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我个人喜欢为每种类型编写一条规则,因为我发现它更容易阅读(特别是如果 htaccess 是您的麻烦),
即
解释不同的位
([a-z0-9-]+) 基本上都是小写字母、数字和连字符。
类似地 ([0-9]+) 仅适用于数字和连字符
希望这有帮助
I personally like to write a rule for each type as I find it clearer to read (especially if htaccess is a bugbear of yours)
i.e.
To explain the different bits
([a-z0-9-]+) is basically all lowercase letters, numbers and hyphens.
Similarily ([0-9]+) is just for numbers and hyphens
Hope this helps