How to create an absolute url on Yii https?

I am creating a website that runs on https. But when I create an absolute URL using

echo Yii::app()->createAbsoluteUrl('site/index'); 

it always returns http://mydomainname.com/site/index .

my expected result is https://mydomainname.com/site/index .

How to create url using https?

+6
source share
5 answers

try it

 Yii::app()->createAbsoluteUrl('site/index', array(), 'https'); 
+16
source

Modify the .htaccess file in the project folder and add these lines. It will redirect all HTTP traffic to https.

 RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://mydomainname.com/$1 [R,L] 
+4
source

Try changing the host

'components' => array (... 'request' => array ('HostInfo' => ' https://mydomainname.com ',), ...),

+3
source

"One shot" is to set https:// in the baseUrl parameter from the configuration:

... 'components' => array( ... 'request' => array( 'baseUrl' => ' https://mydomainname.com/site', ), ... ),

0
source

It is best to create a regular UrlManager implementation, as described here:

http://www.yiiframework.com/wiki/407/url-management-for-websites-with-secure-and-nonsecure-pages

The advantage is that your users do not have to suffer from unnecessary double redirects every time you have a genuine redirect.

0
source

Source: https://habr.com/ru/post/957315/


All Articles