Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Apache mod_重写正则表达式限制匹配最大量词?_Regex_.htaccess_Mod Rewrite_Pcre_Quantifiers - Fatal编程技术网

Regex Apache mod_重写正则表达式限制匹配最大量词?

Regex Apache mod_重写正则表达式限制匹配最大量词?,regex,.htaccess,mod-rewrite,pcre,quantifiers,Regex,.htaccess,Mod Rewrite,Pcre,Quantifiers,我在mod_rewrite regex中使用匹配量词{},如果量词匹配1或2次,则重写规则有效,如果匹配3次或更多次,则不起作用。为什么? 示例.htaccess文件: 这项工作(我需要mydomain.com/download.ex): 但这不起作用,500个错误,只将最大量词改为2到3个(我需要mydomain.com/download.exe): 这太棒了,但它是真实的。为什么会这样 p、 美国。 版本: root@andrey:/var/www/default/www# apache2

我在mod_rewrite regex中使用匹配量词{},如果量词匹配1或2次,则重写规则有效,如果匹配3次或更多次,则不起作用。为什么?

示例.htaccess文件:

这项工作(我需要mydomain.com/download.ex):

但这不起作用,500个错误,只将最大量词改为2到3个(我需要mydomain.com/download.exe):

这太棒了,但它是真实的。为什么会这样

p、 美国。 版本:

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]

如果这是因为无限循环,为什么第一个变量({1,2})工作正常?因为
\.{1,2}
将不匹配
.php
只有当您给出范围>=3时,它才会匹配
.php
。你测试过这个解决方案吗?非常感谢,我理解了这个问题,那么重命名download.php\u download.php
RewriteRule^download\..{1,3}$/\u download.php[L]
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  
RewriteEngine On
RewriteBase /

RewriteRule ^download\.(?!php$).{1,3}$ download.php [L,NC]