As part of product data migration from one store to another i need to change url keys on some of the products. Entire process is being done in shell script.

So imagine i used to have product with following url key: nice-prod1 . It used to be in some category and whatnot. Now, after migration, it has become: nice-prod2. It's accessible by it's new key so everything is fine. But the first one is not working anymore. So what I need, is to create url rewrites that redirect nice-prod1 to nice-prod2.

I tried to achieve this using setData('save_rewrites_history', true); before saving changes in product (which is part of collection), but no url rewrites are generated.

1 Answer 1


Use the admin feature. Go to Catalog → URL Rewrite Management. See this for some more info.

To code it yourself, here is a GIST with the code you need.

Mage::getModel('core/url_rewrite')->setIsSystem(0)->setOptions('RP')->setIdPath('Imported-Old-Website-URL-test1')->setTargetPath('alicia-suspender-skirt-32360')->setRequestPath('SHOPONLINE.aspx?Product=Alicia Skirt&Brand=Lascivious Test&PID=1975')->save();
Mage::getModel('core/url_rewrite')->setIsSystem(0)->setOptions('RP')->setIdPath('Imported-Old-Website-URL-test2')->setTargetPath('alicia-suspender-skirt-32360')->setRequestPath('SHOPONLINE.aspx?Product=Alicia Skirt&Brand=Lascivious Test&PID=1975')->save();
  • How do I get the current rewrite rule(s) for product in case i want to code it myself?
    – Darvex
    Aug 5, 2014 at 18:52
  • Mage::getModel('core/url_rewrite')->getResourceCollection() will give you a collection and/or you can load single records. See app/code/core/Mage/Core/Model/Url/Rewrite.php
    – mbalparda
    Aug 5, 2014 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.