apache mod_rewrite 正则表达式多参数问题

发布于 2024-08-26 00:06:55 字数 752 浏览 5 评论 0原文

正则表达式一直是我的烦恼。每当我以为我终于得到它时,我就会遇到一个新问题!

我想捕获这样的网址:

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 技术交流群。

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

发布评论

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

评论(2

空气里的味道 2024-09-02 00:06:55
RewriteRule ^boutique/(?:[a-zA-Z][\w-]*/){1,3}/(\d+)(?:/(\d+)(?:/(\d+))?)?/?$ boutique.php?c1=$1&c2=$2&c3=$3
RewriteRule ^boutique/(?:[a-zA-Z][\w-]*/){1,3}/(\d+)(?:/(\d+)(?:/(\d+))?)?/?$ boutique.php?c1=$1&c2=$2&c3=$3
鹿港小镇 2024-09-02 00:06:55

我个人喜欢为每种类型编写一条规则,因为我发现它更容易阅读(特别是如果 htaccess 是您的麻烦),

### Rewrite rule for /boutique/blabla-1/bla-bla2/99/104
RewriteRule ^boutique/([a-z0-9-]+)/([a-z0-9-]+)/([0-9]+)/([0-9]+) boutique.php?c1=$3&c2=$4

解释不同的位
([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.

### Rewrite rule for /boutique/blabla-1/bla-bla2/99/104
RewriteRule ^boutique/([a-z0-9-]+)/([a-z0-9-]+)/([0-9]+)/([0-9]+) boutique.php?c1=$3&c2=$4

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

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