繁体   English   中英

Apache mod_rewrite正则表达式中多个匹配的多个反向引用

[英]Multiple backreferences for multiple match in regular expression for Apache mod_rewrite

我需要知道是否有可能在mod_rewrite中使用正则表达式来匹配某个序列的不可预测的次数,并使用对每个匹配项的反向引用来访问这些匹配项。

一个例子可以说很多话:

匹配顺序:

0102030405 ....

(序列长度= n * 2,其中n可以是一个大于或等于1的数字)

正则表达式:

([0-9] [0-9] +)

我需要能够获得序列中的n个匹配项中的每一个,以便在mod_rewrite规则中使用它们,这将提供以下翻译:

/01.html => /01/index.html

/0102.html => /01/02/index.html

/010203.html => /01/02/03/index.html

/01020304.html => /01/02/03/04/index.html

...

可以得到这个吗?

您可以为此使用以下2条规则:

RewriteRule ^(.+?/)?([0-9]{2})\.html$ /$1$2/index.html [L]

RewriteRule ^(.+?/)?([0-9]{2})([0-9]+.+?\.html)$ /$1$2/$3 [L]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM