Fixed incorrect HTTPS detection.

Backport from Yii2: https://github.com/yiisoft/yii2/commit/66e698673d1fb95222d160f3948d23b8d6372940

Yii2 issue: https://github.com/yiisoft/yii2/issues/457