正则表达式中的查询字符串条件
用户重定向
page.php?letter=A&num=2
我想将来自以下地址的
/static/A/2
:我尝试使用以下正则表达式:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^letter=([a-zA-Z]+$)&num=([0-9]+$) [NC]
RewriteRule ^page.php static/%1/%2? [NC,R=301,L]
但它不起作用...在我看来,第一个表达式 ([a-zA-Z]+ $)
“捕获” URL 中的 &num=... ,这就是它搞乱条件的原因:/
有什么想法可以纠正这个条件吗?
谢谢!
乔尔
I want to redirect a user who gets from
page.php?letter=A&num=2
to the following address:
/static/A/2
I tried using the following regex:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{QUERY_STRING} ^letter=([a-zA-Z]+$)&num=([0-9]+$) [NC]
RewriteRule ^page.php static/%1/%2? [NC,R=301,L]
But it doesn't work... It seems to me like the first expression ([a-zA-Z]+$)
"catches" the &num=... as well in the URL and that is why it messes up the condition :/
Any ideas how to correct this condition?
Thanks!
Joel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能应该删除括号末尾的
$
,因为它在正则表达式中通常意味着“匹配行尾”。所以你的
RewriteCond
将是:You should probably remove the
$
at the end of the parentheses, as it usually means "match the end of line" in regular expressions.So your
RewriteCond
would be: