I’ve tested different redirect options for .htaccess, but sites keep giving “redirected you too many times” error. Here is the working code to solve the problem.
In the file /config/web.php you need to find:
'bootstrap' => [ 'log', 'app\components\Bootstrap', ],
and place below:
'on beforeRequest' => function ($event) { if(!Yii::$app->request->isSecureConnection){ $url = Yii::$app->request->getAbsoluteUrl(); $url = str_replace('http:', 'https:', $url); Yii::$app->getResponse()->redirect($url); Yii::$app->end(); } },