【问题标题】:Codeigniter's redirect() and non-standard urlsCodeigniter 的 redirect() 和非标准 url
【发布时间】:2012-07-02 07:21:05
【问题描述】:

Codeigniter 不会正确重定向“url”oauth://application,将其固定在当前域之后,如下所示:

http://mywebsite.com/index.php/oauth://application

代码如下:

redirect("oauth://application", "location"); // changing to refresh doens't work either.

知道如何让它工作吗?我正在尝试重定向到 Android 应用。

非常感谢。

【问题讨论】:

    标签: php codeigniter redirect


    【解决方案1】:

    还不如使用PHP原生的header函数:

    header('Location: oauth://application', TRUE, 302);
    exit;
    

    如果你想调整 CI 的功能,只需创建 application/helpers/my_url_helper.php 并调整 preg_match URL 检查:

    function redirect($uri = '', $method = 'location', $http_response_code = 302)
    {
        // if ( ! preg_match('#^https?://#i', $uri))
        if ( ! preg_match('#^(https?|oauth)://#i', $uri))
        {
            $uri = site_url($uri);
        }
    
        switch($method)
        {
            case 'refresh'  : header("Refresh:0;url=".$uri);
                break;
            default         : header("Location: ".$uri, TRUE, $http_response_code);
                break;
        }
        exit;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-19
      • 2011-04-06
      • 1970-01-01
      • 2016-02-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多