As @Aric Watson states: you cannot do this with plain
.htaccess, because the
category-name-slug will not be predictable from
But... assuming you're only interested in creating 301's to the new URL's you don't actually need to know the new URL. A 301 to
/catalog/product/view/id/[product id] would do as well, given that the canonical of your product detail page is set correct. So you won't lose any SEO value there.
In that scenario, you could write a script that writes those redirects according to a CSV that maps your old URL to the new product ID.
This function could look something like this:
* Import rule for Magento Community
* @param $fromUrl
* @param $toUrl
public function createRuleCommunity($fromUrl, $toUrl)
// Create rewrite:
/** @var Mage_Core_Model_Url_Rewrite $rewrite */
$rewrite = Mage::getModel('core/url_rewrite');
// Check for existing rewrites:
foreach($this->storeIds as $storeId)
// Attempt loading it first, to prevent duplicates:
In this method, you could set
/catalog/product/view/id/[product id]. But you could also set the new URL-key of the product, if you got that already. If you have the product ID, a simple
$urlKey = Mage::getModel('catalog/product')->load($id)->getUrlKey() would do.