Requirement
How to forcibly redirect to https (redirect if user accessing http) on Yii2? I already tried web.config to force https, but it didn't work.
scenario
I am using Yii2 advanced app hosted on IIS 7.5.
Requirement
How to forcibly redirect to https (redirect if user accessing http) on Yii2? I already tried web.config to force https, but it didn't work.
scenario
I am using Yii2 advanced app hosted on IIS 7.5.
Its actually very easy in Yii2 as there is a predefined method for your check. Just three steps needed:
1. Extend the application class
Extend the default yii web-application class and override the
handleRequest
-method. Use the existing Yii2-function to check if the connection is secure.2. Use new class in index.php
Within the
index.php
of yourweb
-folder simply use your new application-class instead of the regular one where the application-instance is created.3. Done!
That's it actually... :)! Hope it helps!
It's very simple on IIS. Can use rewrite module to solve this issue. E.g.,
It's very effective and fast. Can used for CDN url of our own without help of PHP code.
This code can used for ASP.Net also. In such case, remove Hide Yii Index section.