Reputation: 3038
I need to know if it is possible, having a regular expression, used in a mod_rewrite, to match a non-predictable number of times a certain sequence and access the matches using a backreference to each of them.
An example avails more than many words:
sequence to match:
0102030405....
(sequence length= n*2, where n could be a number greater or equal to 1)
regular expression:
([0-9][0-9]+)
I would need to be able to get each of the n matches in the sequence, in order to use them in a mod_rewrite rule, that would give the following translations:
/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
...
Would that be possible to get this?
Upvotes: 1
Views: 984
Reputation: 785156
You can use these 2 rules for that:
RewriteRule ^(.+?/)?([0-9]{2})\.html$ /$1$2/index.html [L]
RewriteRule ^(.+?/)?([0-9]{2})([0-9]+.+?\.html)$ /$1$2/$3 [L]
Upvotes: 1