Skip to content

Instantly share code, notes, and snippets.

@ryaan-anthony
Created November 7, 2015 21:11
Show Gist options
  • Save ryaan-anthony/35e9f8db3397afcb712a to your computer and use it in GitHub Desktop.
Save ryaan-anthony/35e9f8db3397afcb712a to your computer and use it in GitHub Desktop.
<?php
/**
* @param string
* @param string
* @param Mage_Core_Model_Store
* @throws Exception
*/
function createRedirect($fromUrl, $toUrl, Mage_Core_Model_Store $store)
{
/** @var Enterprise_UrlRewrite_Model_Redirect $redirect */
$redirect = Mage::getModel('enterprise_urlrewrite/redirect');
$redirect->loadByRequestPath($fromUrl, $store->getId());
$redirect->setStoreId($store->getId());
$redirect->setOptions('RP');//RP=301, R=302
$redirect->setIdentifier($fromUrl);
$redirect->setTargetPath($toUrl);
$redirect->setEntityType(Mage_Core_Model_Url_Rewrite::TYPE_CUSTOM);
$redirect->save();
}
$redirects = [
// "from" => "to",
];
include '../app/Mage.php';
$store = Mage::app()->getStore(1);
foreach ($redirects as $fromUrl => $toUrl) createRedirect($fromUrl, $toUrl, $store);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment