为什么此模式与 RewriteCond 中的 QUERY_STRING 不匹配,而在 preg_match 中匹配?
这是我的 .htaccess
文件中的内容。
RewriteEngine on
RewriteCond %{QUERY_STRING} ^(run=[a-z0-9A-z]{13})$
RewriteRule %{QUERY_STRING} \? [L]
我所做的就是为所有 QUERY_STRING
重写类似于 run=4f13665700694
的 QUERY_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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这与第二行有关。尝试将其更改为:
I think it has something to do with the second line. Try changing it to: