Q:

.htaccess redirect: Capture portion of URL

Given the following URL:
www.example.com/old/items/itemid/detail

Now say I want to redirect requests for that to the following location:
www.example.com/new/product/location/itemid

...where 'itemid' is, of course, dynamic but will always be a sequence of exactly four numbers.
How do I create a redirect rule in .htaccess that will "capture" the 'itemid' from the original URL and redirect to the new location with the same itemid at the end of the URL?

A:

RewriteRule ^old/items/(\d*)/detail$ /new/product/locations/$1 [L,R=301]

should work but I haven't tried it. Basically, (\d*) matches an arbitrary length of digits and that match can be re-used using $1. 

