.htaccess重定向:捕获URL的一部分

时间:2012-08-23 20:10:44

标签: regex .htaccess redirect capture

给出以下网址:

www.example.com/old/items/itemid/detail

现在说我想将请求重定向到以下位置:

www.example.com/new/product/location/itemid

...其中'itemid'当然是动态的,但总是四个数字的序列。

如何在.htaccess中创建一个重定向规则,该规则将从原始网址“捕获”'itemid'并重定向到网址末尾带有相同itemid的新位置?

1 个答案:

答案 0 :(得分:2)

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

应该可以工作,但我还没试过。基本上,(\d*)匹配任意长度的数字,并且可以使用$1重复匹配。

相关问题