So today I had to import a bunch of 301 redirects in Magento Enterprise. Needless to say, I’m saving this one for myself, but also for you: my fellow readers…
The method to programmatically create (or import) 301 redirects into Magento Enterprise is as follows:
* Import rule:
* @param $fromUrl
* @param $toUrl
public function createRule($fromUrl, $toUrl)
// Create rewrite:
/** @var Enterprise_UrlRewrite_Model_Redirect $rewrite */
$rewrite = Mage::getModel('enterprise_urlrewrite/redirect');
// Check for existing rewrites:
foreach($this->storeIds as $storeId)
// Attempt loading it first, to prevent duplicates:
Redirect to the homepage
If you need to redirect to the homepage, you can simply set the $toUrl to index.php or the URL identifier of your homepage. Setting it to ‘/’ wont work. I bumped into this one because a lot of 301 redirects redirected to the homepage, since the product in question no longer existed on the new website.
Looking for a way to import 301 redirects into Magento Community. Here’s how!
Visitors give this article an average rating of 3.9 out of 5.
How would you rate this article?
★ ★ ★ ★ ★