Magento URL Redirect from Controller

https://www.apptha.com/blog/magento-url-redirect-from-controller/


_redirect()

This function is the key which helps to redirect between Magento modules.

Example:

<?php
// $this->_redirect('module/controller/action');
$this->_redirect('customer/account/login');
?>

We can redirect within our current controller by specifying ‘*’. Here is the example,

<?php
$this->_redirect('*/*/success');
?>

In the above mentioned code, the first ‘*’ specifies current ‘Module’, the second ‘*’ specifies current ‘Controller‘ and ‘success’ refers to the ‘Action‘. But, this _redirect() function will help to redirect within magento stores only (module/controller/action) which means there is no possibility to redirect requests to an external URL(like http://contus.com).

Now, let us look at the method to redirect requests to external URLs

_redirectUrl()

This is the key function which helps to redirect our action to external URL outside Magento base. Using this function, we can either use Magento’s method or can pass full path like http://contus.com to redirect.
Here is the example,

<?php
$this->_redirectUrl('customer/account/login');
// or
$this->_redirectUrl('http://contus.com');
?>

Note: Try out the codes mentioned below if both of the previously mentioned suggestions don’t work.

<?php
Mage::app()->getResponse()->setRedirect($url)->sendResponse();
// or
Mage::app()->getFrontController()->getResponse()->setRedirect($url)->sendResponse();
?>

Other useful codes that would help:
For creating a secured URL:

Mage::getUrl('customer/account/login', array('_secure' => true));

For passing parameters with the URL:

Mage::getUrl('customer/account/login', array('_secure' => true, 'parameter_name'=>'value', 'param2'=>'val'));

For getting parameters from the URL:
we can get the parameters value using

$this->getRequest()->getParam('parameter_name');

Raise your queries as questions in our forum to get clarifications from certified Magento developers Support Forum.

Let us know your feedback in the comments section provided below.

- See more at: https://www.apptha.com/blog/magento-url-redirect-from-controller/#sthash.Q32pioEf.dpuf
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值