You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by wi <ic...@gmail.com> on 2007/08/06 17:57:31 UTC

[users@httpd] RewriteRule advice

Hi all

I need to create a rule to map requests such as

/names/123/data

to

/names/1/2/3/data

I can't control how many digits I need to split up like this, which is where
my regex skillz are breaking down.

Any ideas?

thanks
Wayne

-- 
2X7 -> %A-3+ -> %K-7+ -> %9-?+ -> %Q-8 -> ?9-?9+

Re: [users@httpd] RewriteRule advice

Posted by Joshua Slive <jo...@slive.ca>.
On 8/6/07, wi <ic...@gmail.com> wrote:
> Hi all
>
> I need to create a rule to map requests such as
>
> /names/123/data
>
> to
>
> /names/1/2/3/data
>
> I can't control how many digits I need to split up like this, which is where
> my regex skillz are breaking down.

RewriteRule ^/names/([0-9]/)*([0-9])([0-9])(.*) /names/$1$2/$3$4 [N]

Because the N flag is used to make the rule loop, you'll need to be
VERY careful if you have any other RewriteRules, since they'll ALL be
reapplied. If you have other RewriteRules that you don't want to loop,
you could just repeat (copy-past) the above RewriteRule (without the
[N] flag) up to the maximum number of digits you'll need to replace.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org