正则表达式中的查询字符串条件

发布于 2024-10-03 09:54:43 字数 480 浏览 0 评论 0原文

用户重定向

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

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

发布评论

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

评论(1

北笙凉宸 2024-10-10 09:54:44

您可能应该删除括号末尾的 $ ,因为它在正则表达式中通常意味着“匹配行尾”。

所以你的RewriteCond将是:

RewriteCond %{QUERY_STRING} ^letter=([a-zA-Z]+)&num=([0-9]+) [NC]

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:

RewriteCond %{QUERY_STRING} ^letter=([a-zA-Z]+)&num=([0-9]+) [NC]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文