Windows Server 2008 上 helicon ape 的正则表达式问题

发布于 2024-10-02 04:22:57 字数 740 浏览 0 评论 0原文

我有以下重写规则:

RewriteRule ^([a-zA-Z0-9]*)/([a-zA-Z0-9]*)\\.php\?(.*)  /$2.php?shop=$1&$3 [NC,L]
RewriteRule ^([a-zA-Z0-9]*)/([a-zA-Z0-9]*)\\.php        /$2.php?shop=$1 [NC,L] 
RewriteRule ^([a-zA-Z0-9]*)/$  /index.php?shop=$1 [L,NC] 
RewriteRule ^([a-zA-Z0-9]*)$   /index.php?shop=$1 [L,NC] 

结果应该重定向以下内容:

www.site.com/Sells 
    -> /index.php?shop=Sells [works] 

www.site.com/Sells/menu.php?Cat=1 
    -> /menu.php?shop=Sells&Cat=1 [failing] 
    -> /menu.php?shop=Sells [which is 'wrong'] 

最后一个示例应该通过重写[1]匹配...

我已经测试了规则ape 附带的正则表达式测试器发现转义 ?. 似乎不起作用。我有点困惑,很感激任何人 可以解释为什么这种转义不起作用。

预先表示感谢。

I have the following rewrite rules:

RewriteRule ^([a-zA-Z0-9]*)/([a-zA-Z0-9]*)\\.php\?(.*)  /$2.php?shop=$1&$3 [NC,L]
RewriteRule ^([a-zA-Z0-9]*)/([a-zA-Z0-9]*)\\.php        /$2.php?shop=$1 [NC,L] 
RewriteRule ^([a-zA-Z0-9]*)/$  /index.php?shop=$1 [L,NC] 
RewriteRule ^([a-zA-Z0-9]*)$   /index.php?shop=$1 [L,NC] 

The result of which should redirect the following:

www.site.com/Sells 
    -> /index.php?shop=Sells [works] 

www.site.com/Sells/menu.php?Cat=1 
    -> /menu.php?shop=Sells&Cat=1 [failing] 
    -> /menu.php?shop=Sells [which is 'wrong'] 

The last example should get matched by rewrite [1]...

I have tested the rules with the regex tester shipped with ape and found that escaping ? and . don't seem to work. I am a little flummoxed and would appreciate anyone who
could shed some light on why this escaping is not working.

Loads of thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

逆光飞翔i 2024-10-09 04:22:57
RewriteRule ^([a-zA-Z0-9]*)/([a-zA-Z0-9]*)\\.php\?(.*)  /$2.php?shop=$1&$3 [NC,L]
RewriteRule ^([a-zA-Z0-9]*)/([a-zA-Z0-9]*)\\.php        /$2.php?shop=$1 [NC,L] 

逃避太多了。将 \\.php 更改为 \.php

RewriteRule ^([a-zA-Z0-9]*)/([a-zA-Z0-9]*)\\.php\?(.*)  /$2.php?shop=$1&$3 [NC,L]
RewriteRule ^([a-zA-Z0-9]*)/([a-zA-Z0-9]*)\\.php        /$2.php?shop=$1 [NC,L] 

Too much escaping. Change \\.php to \.php.

独守阴晴ぅ圆缺 2024-10-09 04:22:57

你似乎逃避了“逃避”的意思。 (你有 \. ,它被读作 \ 和任何字母/符号)

You seem to escape the \ that is meant to escape the . (you have \. which is read as \ and any letter/symbol)

烂人 2024-10-09 04:22:57

QSA 标志丢失!它附加了查询字符串,但我忘了将其放入!

我作为预览添加的双斜杠没有显示单斜杠!

QSA flag was missing! it appends the query string and I forgot to put it in!!!

The double slashes I added as preview was not showing the single ones!

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