Yii Controller Force HTTPS

Luc*_*nto 7 php yii

我想知道如何在Yii Controller Action强制使用HTTPS(SSL).

Bog*_*rym 7

看一下这篇文章http://www.yiiframework.com/forum/index.php/topic/25407-forcing-https-in-yii/

class HttpsFilter extends CFilter {
    protected function preFilter( $filterChain ) {
        if ( !Yii::app()->getRequest()->isSecureConnection ) {
            # Redirect to the secure version of the page.
            $url = 'https://' .
                Yii::app()->getRequest()->serverName .
                Yii::app()->getRequest()->requestUri;
                Yii::app()->request->redirect($url);
            return false;
        }
        return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

即使了解更多详情.

  • 这是另一种情况.创建自定义URL管理器以分离安全/不安全的路由是最好的解决方案,试试这篇优秀的文章http://www.yiiframework.com/wiki/407/url-management-for-websites-with-secure-和 - 非安全页面/.请不要难过.你刚才第一次描述了你的问题. (2认同)