Magento Redirect Functions

Magento Redirect Functions

Magento is the most preferred solutions for the eCommerce merchants in the current market scenario. Considering the importance of Magento’s usage, here in this article, we will see how Magento core’s inbuilt redirects function to redirect ‘url’ to a new ‘url’ in Magento.
Few of them are stated below:
You can redirect the user to any URL from any of your Magento controllers, as stated below:
In reference: “Protected function_redirectUrl($url)”

$url = " https://www.appseconnect.com/contact/ "

$this->_redirectUrl($url); 
else,
Mage::app()->getFrontController()->getResponse()->setRedirect($url);

 

In case, Magento is not redirecting to the new URL then set your redirecting URL and then call function send response().

Mage::app()->getFrontController()->getResponse()->setRedirect($url)->sendResponse();

 

On other hand, you can simply pass URL path instead of full URL mentioned in the table below:
This is in reference to the “protected function_redirect($path, $arguments = array())”

$path = "contact-us";
$arguments = array('insync1' => 'value1');
$url = Mage::getUrl($path, $arguments);
$this->_redirect($path, $arguments );
Mage::app()->getFrontController()->getResponse()->setRedirect($url);

 

Here you can even redirect to internal success page:
This is in reference to the “protected function _redirectSuccess($defaultUrl)”

$this->_redirectSuccess($successUrl);
// note: it should be internal url otherwise it will redirect to base url

 

You can also redirect to internal error page like;
This is in reference to the “protected function _redirectError($defaultUrl)”

$this->_redirectError($errorUrl);
// Note: it must be internal url

 

Now, you can redirect to referrer URL:
This is in reference to the “protected function _redirectReferer($defaultUrl)”

$this->_redirectReferer($refererUrl);
// $refererUrl is only used if no referrer found, otherwise it will redirect to original referrer

 

For your information, functions used above will appear on the source file.
Source: app\code\core\Mage\Core\Controller\Varien\Action.php

/**
* Set redirect url into response
*
* @param string $url
* @return  Mage_Core_Controller_Varien_Action
*/
protected function _redirectUrl($url)
{
$this->getResponse()->setRedirect($url);
return $this;
}
/**
* Set redirect into response
*
* @param  string $path
* @param  array $arguments
* @return  Mage_Core_Controller_Varien_Action
*/
protected function _redirect($path, $arguments = array())
{
return $this->setRedirectWithCookieCheck($path, $arguments);
}
/**
* Redirect to success page
*
* @param string $defaultUrl
* @return Mage_Core_Controller_Varien_Action
*/
protected function _redirectSuccess($defaultUrl)
{
$successUrl = $this->getRequest()->getInsync(self::PARAM_NAME_SUCCESS_URL);
if (empty($successUrl)) {
$successUrl = $defaultUrl;
}
if (!$this->_isUrlInternal($successUrl)) {
$successUrl = Mage::app()->getStore()->getBaseUrl();
}
$this->getResponse()->setRedirect($successUrl);
return $this;
}
/**
* Redirect to error page
*
* @param string $defaultUrl
* @return  Mage_Core_Controller_Varien_Action
*/
protected function _redirectError($defaultUrl)
{
$errorUrl = $this->getRequest()->getParam(self::PARAM_NAME_ERROR_URL);
if (empty($errorUrl)) {
$errorUrl = $defaultUrl;
}
if (!$this->_isUrlInternal($errorUrl)) {
$errorUrl = Mage::app()->getStore()->getBaseUrl();
}
$this->getResponse()->setRedirect($errorUrl);
return $this;
}
/**
* Set referer url for redirect in response
*
* @param   string $defaultUrl
* @return  Mage_Core_Controller_Varien_Action
*/
protected function _redirectReferer($defaultUrl=null)
{
$refererUrl = $this->_getRefererUrl();
if (empty($refererUrl)) {
$refererUrl = empty($defaultUrl) ? Mage::getBaseUrl() : $defaultUrl;
}
$this->getResponse()->setRedirect($refererUrl);
return $this;
}

Integrate your ERP with eCommerce stores, Marketplace and CRM

Search

Free Trial / Demo

Try the APPSeCONNECT Integration Platform for 30 Days or request a free demo.

Related Posts

appseconnect-New-Logo_2022.png

Book a Demo

Get a personalized solution for your business needs with our free integration consultation and demo.

1200+ Companies rely on APPSeCONNECT to drive growth through automation

⚡ Take the first step towards seamless integration
appseconnect-New-Logo_2022.png

Start Your Automation Journey With Pre-Built Connectors.

Get a Demo. Try it Free.

G2 Summer Badges 2023
we use cookies
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies.