Created
November 7, 2015 21:11
-
-
Save ryaan-anthony/35e9f8db3397afcb712a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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