为什么此模式与 RewriteCond 中的 QUERY_STRING 不匹配,而在 preg_match 中匹配?

发布于 2024-12-26 22:04:44 字数 1010 浏览 3 评论 0原文

这是我的 .htaccess 文件中的内容。

RewriteEngine on

RewriteCond %{QUERY_STRING}  ^(run=[a-z0-9A-z]{13})$
RewriteRule %{QUERY_STRING}  \? [L]

我所做的就是为所有 QUERY_STRING 重写类似于 run=4f13665700694QUERY_STRING 并且什么都不做。 URL 示例:http://thinkingmonkey.me/runs/?run=4f13665700694。因此,RewriteCond 应该匹配。但上面的方法不起作用。

但是,这个模式似乎是正确的。因为,preg_match & RewriteRule 使用PCRE - Perl 兼容正则表达式

我使用 preg_match 尝试过。

$subject = "run=4f13665700694"; 
$pattern = "/^(run=[a-z0-9A-z]{13})$/";

echo preg_match($pattern, $subject);

如上所述,上面将输出:

1

即成功匹配。

我不明白为什么。我在这里缺少什么?

Here is what I have in my .htaccess file.

RewriteEngine on

RewriteCond %{QUERY_STRING}  ^(run=[a-z0-9A-z]{13})$
RewriteRule %{QUERY_STRING}  \? [L]

All I am doing is Rewriting the QUERY_STRING for all QUERY_STRING similar to run=4f13665700694 and do nothing. A URL example: http://thinkingmonkey.me/runs/?run=4f13665700694. So, the RewriteCond should Match. But the above does not work.

But, the pattern seemed correct. Since, both preg_match & RewriteRule use PCRE - Perl Compatible Regular Expressions.

I tried it using preg_match.

$subject = "run=4f13665700694"; 
$pattern = "/^(run=[a-z0-9A-z]{13})$/";

echo preg_match($pattern, $subject);

And as excepted the above will output:

1

i.e. a successful match.

I do not understand why. What am I missing here?

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

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

发布评论

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

评论(1

溺孤伤于心 2025-01-02 22:04:44

我认为这与第二行有关。尝试将其更改为:

RewriteRule ^(.*) $1?

I think it has something to do with the second line. Try changing it to:

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