Magento: Redirect functions

原文:http://blog.chapagain.com.np/magento-redirect-functions/

The redirect functions are present in Mage_Core_Controller_Varien_Action class.

/* Redirect to certain url */
_redirectUrl($url)

/* Redirect to certain path */
_redirect($path, $arguments=array())

/* Redirect to success page */
_redirectSuccess($defaultUrl)

/* Redirect to error page */
_redirectError($defaultUrl)

/* Set referer url for redirect in response */
_redirectReferer($defaultUrl=null)

/* Identify referer url via all accepted methods (HTTP_REFERER, regular or base64-encoded request param) */
_getRefererUrl()

/* Check url to be used as internal */
_isUrlInternal($url)

Example:

You can use the redirect functions in your controller class. Like below:-

$this->_redirect($path, $arguments=array());
// OR,
$this->_redirectUrl($url);
1
2
3
$this->_redirect($path, $arguments=array());
// OR,
$this->_redirectUrl($url);
The other way is:-

For redirect URL:-

$url = "http://example.com";
Mage::app()->getFrontController()->getResponse()->setRedirect($url);
1
2
$url = "http://example.com";
Mage::app()->getFrontController()->getResponse()->setRedirect($url);
For redirect with path and arguments:-

Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl($path, $arguments));
1
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl($path, $arguments));
Hope it helps. Thanks.

magento 强制跳转404

原文:http://blog.csdn.net/yy20071313/article/details/43852879

$this->getResponse()->setHeader('HTTP/1.1','404 Not Found');
$this->getResponse()->setHeader('Status','404 File not found');
$this->_forward('defaultNoRoute');

#magento# 之 redirectuRL

http://blog.sina.com.cn/s/blog_6ea2cfe40101e1er.html

1.
  
    protected function _redirect($path, $arguments = array())
    {
        return $this->setRedirectWithCookieCheck($path, $arguments);
    }

2.
    
    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;
    }

3.
   
    protected function _redirectReferer($defaultUrl=null)
    {

$refererUrl = $this->_getRefererUrl();
        if (empty($refererUrl)) {
            $refererUrl = empty($defaultUrl) ? Mage::getBaseUrl() : $defaultUrl;
        }

$this->getResponse()->setRedirect($refererUrl);
        return $this;
    }

4.
   
    protected function _redirectSuccess($defaultUrl)
    {
        $successUrl = $this->getRequest()->getParam(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;
    }

5.
   
    protected function _redirectUrl($url)
    {
        $this->getResponse()->setRedirect($url);
        return $this;
    }

6.
  
    protected function _rewrite()

7.
    
    protected function _getRefererUrl()
    {
8.
    
    protected function _forward($action, $controller = null, $module = null, array $params = null)
    {

#############example################
 Mage::app()->getFrontController()->getResponse()->setRedirect('http://www.google.com');

magento 跳转的更多相关文章

  1. magento 自定义url路径 和 filter data 小结

    背景是往一个第三方的搜索插件里面加入filter功能. 首先是路径,插件自己定义了一个router,类似于cms.那首先说说router好了,从入口一路追查的话,会发现最后进入的是Mage_Core_ ...

  2. 安装完magento后,其他电脑无法访问magento,URL自动跳转到http://localhost/magento

    问题:在电脑A上安装完了magento 1.7.0.2 然后, 在电脑A上用 http://localhost/magento 访问网站,没有问题. 但在电脑B 上用 http://192.168.4 ...

  3. 【解决方法】magento paypal快速结账 不跳转

    magento paypal Express Checkout(快速结账) 页面不跳转到Paypal的解放方法 我使用的magento 1.9.0.1 版本的,Paypal 快速结账都已经设置完毕,但 ...

  4. magento产品成功添加到购物车后跳转到不同页面 添加 add to cart 按钮

    1 添加产品到购物车成功后是跳转到购物车页面或不跳转.这个在后台可以设置 system -> configuration -> After Adding a Product Redirec ...

  5. magento getUrl函数跳转admin模块问题

    在用以下代码时,跳转后的url里面会是空的,即没有admin这个值 $this->getUrl('admin/catalog_product/edit', array('id' => $c ...

  6. magento后台登陆后,没任何提示,又跳转到登陆页面

    这个问题通常是cookie配置的问题.需要去将core_config_data中web/cookie/cookie_path.web/cookie/cookie_domain设为null

  7. LNMP环境magento常见错误

    一.安装报404错误 git clone 下最新代码,跳转到index/install 安装时出现404错误 需要把伪静态规则加到nginx配置文件中: # # The default server ...

  8. magento后台paypal设置

    如何在magento后台设置paypal呢? 这边把整理的简单跟大家分享一下. 1.system->config-paypel1.1 Merchant Country 设置国家1.2 Email ...

  9. magento cache,magento index

    "Magento后台作修改,Magento前台没变化""Magento属性更新了,Magento前台没反应"如果你碰到了以上两种情况,或者看到截图中的提示: 您 ...

随机推荐

  1. Linux主机通过windows虚拟机上网

    现在有些公司喜欢把网络接入和安全管理揉在一起管理,放着标准的协议不用,偏偏要采用某些厂商自己搞的所谓的"一整套解决方案".这些所谓的解决方案又常常只顾着windows.对非软件行业 ...

  2. shell script 二 判断符号【】 shift 偏移量 if then fi

    判断符号[]类似于test.但是[]有通配符及正则表达式,为了区分,利用[]来做判断时,前后都需要加空格来区分.又一个坑 [ -z "$HOME" ];echo $? 例: 1 r ...

  3. 使用ReadStream方法读取文件事件传递过程

    const fs = require('fs'); let file = fs.createReadStream("filename.js"); file.on("ope ...

  4. 一句话的Android增量更新框架(增量更新)

    转自:http://www.jianshu.com/p/a9ec8fa780e2 Android应用更新要使用完整的新版本Apk安装,增量更新则是提供一个新旧版本偏差数据的patch包供应用下载,然后 ...

  5. 39th 迷迷糊糊 二豆玩不转了

    今天学的语法 1.   #  {} . format()的传送作用 请从键盘获取一个整数,求他的平方根,要求: 1 如果这个整数是大于等于0,则直接打印其平方根 2 否则, 打印其绝对值的平方根 x ...

  6. 【leetcode】133. Clone Graph

    题目如下: Given the head of a graph, return a deep copy (clone) of the graph. Each node in the graph con ...

  7. C/C++ fgets

    {     str_normalize_init();    unsigned options = SNO_TO_LOWER | SNO_TO_HALF;    if (argc > 1)    ...

  8. C# 调用c++数据类型对应

    C#调用 非托管C++ dll 传入Stringbuilder.ref string . ref char 等都报错,如mscorlib.dll 异常.其他信息: 尝试读取或写入受保护的内存.这通常指 ...

  9. Vue学习笔记【20】——Vue中的动画(使用动画钩子函数)

    定义及使用钩子函数 定义 transition 组件以及三个钩子函数:  <div id="app">    <input type="button&q ...

  10. Shiro学习(6)Realm整合

    6.1 Realm [2.5 Realm]及[3.5 Authorizer]部分都已经详细介绍过Realm了,接下来再来看一下一般真实环境下的Realm如何实现. 1.定义实体及关系 即用户-角色之间 ...