简体   繁体   English

强制对自定义页面使用Https

[英]Force Https for custom pages

I followed the following tutorial: Yii 1.1: URL management for Websites with secure and nonsecure pages 我遵循以下教程: Yii 1.1:具有安全和不安全页面的网站的URL管理

This is code from /protected/config/main.php 这是来自/protected/config/main.php代码

'urlManager'=>array(
    'class' => 'UrlManager',
    'hostInfo' => 'http://goliv.me',
    'secureHostInfo' => 'https://goliv.me',
    'secureRoutes' => array(
        'site/booking',   // site/login action
    ),
    'urlFormat' => 'path',
    'showScriptName' => false, 
    'caseSensitive' => false, 
    'urlSuffix' => '.html',
    'rules' => array(
        '<controller:\w+>/<id:\d+>'=>'<controller>/view',
        '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
        '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
        '<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>'
    ),
),

and this my .htaccess file: 这是我的.htaccess文件:

RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php

I'm facing the following problem only with site/booking : 我仅在site/booking面临以下问题:

This webpage has a redirect loop 此网页有重定向循环

When I remove this part: 当我删除此部分时:

'secureRoutes' => array(
    'site/booking'
),

Everything works without problems. 一切正常,没有问题。

Any solutions? 有什么办法吗?

The Method does not correcty return true if there is a slash at the end of the route, thus calling site/booking/ will not return true. 如果路线末端有斜线,则该方法不会正确返回true,因此调用site / booking /不会返回true。

class UrlManager extends CUrlManager
{
................
/**
     * @param string the URL route to be checked
     * @return boolean if the give route should be serviced in SSL mode
     */
    protected function isSecureRoute($route)
    {
        if ($this->_secureMap === null) {
            foreach ($this->secureRoutes as $r) {
                $this->_secureMap[strtolower($r)] = true;
            }
        }
        $route = strtolower($route);
        if (isset($this->_secureMap[$route])) {
            return true;
        } else {
            return ($pos = strpos($route, '/')) !== false 
                && isset($this->_secureMap[substr($route, 0, $pos)]);
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM