我在mod_rewrite regex中使用匹配限定符{},如果限定符匹配1或2次,则重写规则有效,如果匹配3次或更多次,则不起作用。为什么?
示例.htaccess文件:
这项工作(我需要mydomain.com/download.ex):
RewriteEngine On
RewriteRule ^download..{1,2}$ /download.php [L]
但这不起作用,500错误,只更改了2到3个最大量词(我需要mydomain.com/download.exe):
RewriteEngine On
RewriteRule ^download..{1,3}$ /download.php [L]
这太棒了,但它是真实的。为什么会这样?
p.s。版本:
root@andrey:/var/www/default/www# apache2 -v
Server version: Apache/2.4.7 (Ubuntu)
Server built: Jul 22 2014 14:36:38
root@andrey:/var/www/default/www# uname -a
Linux mydomain.com 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
root@andrey:/var/www/default/www# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.1 LTS
Release: 14.04
Codename: trusty
Regex .{1,3}
工作正常,但不工作,因为它也匹配/download.php
,并导致mod_rewrite无限循环,从而导致500错误。
为了克服这一点,当扩展为.php
:时,进行负面展望以停止重写
RewriteEngine On
RewriteBase /
RewriteRule ^download.(?!php$).{1,3}$ download.php [L,NC]