views:

55

answers:

2

I am using the following code to attempt to redirect a dynamic URL to a new dynamic URL, under the same domain:

RewriteRule ^products/item/^\d([^/]+) /product/$1/ [R=301,L]

I've tried these too:

RewriteRule ^products/item/[^\d]([^/]+) /product/$1/ [R=301,L]
RewriteRule ^products/item/[0-9]([^/]+) /product/$1/ [R=301,L]

But this was redirecting /products/item/342/ to /product/42/, I tested this on a larger number (e.g. 123456789) and it redirected to /product/23456789/.

It would appear that my rule is not picking up the firsts digit, can anyone help me resolve this?

I've also tried using [\d] instaled of [0-9], but this has the same problem.

Cheers!

+3  A: 

Try

RewriteRule ^products/item/(\d[^/]+) /product/$1/ [R=301,L]
yogsototh
Genius! That got it ;), many thanks for your answer!
ILMV
this was the group in the regexp that caused problem. $1 will match all which is within parenthesis.
yogsototh
A: 
RewriteRule ^products/item/([0-9]+) /product/$1/ [R=301,L]
Coronatus