3

私は mod_rewrite regex で match quantifier {} を使用しています。rewrite ルールは、quantifier が 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]

それは素晴らしいですが、これは本物です。なぜそうなのですか?

バージョン:

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  
4

1 に答える 1

0

Regex \.{1,3} is working fine but it is not working because it also matches /download.php and causes mod_rewrite to loop infinitely thus resulting in 500 error.

To overcome this have a negative lookahead to stop rewriting when extension is .php:

RewriteEngine On
RewriteBase /

RewriteRule ^download\.(?!php$).{1,3}$ download.php [L,NC]
于 2014-11-13T06:03:24.583 に答える