php 如何在 Yii https 上创建绝对 url?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19761689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create absolute url on Yii https?
提问by Mahesh Eu
I am creating a website which runs on https.. But when i create absolute url using
我正在创建一个在 https 上运行的网站。但是当我使用创建绝对 url
echo Yii::app()->createAbsoluteUrl('site/index');
it always return http://mydomainname.com/site/index.
它总是返回http://mydomainname.com/site/index。
my expected output is https://mydomainname.com/site/index.
我的预期输出是https://mydomainname.com/site/index。
How can i create a url with https ?
如何使用 https 创建网址?
回答by Neophile
Try this
尝试这个
Yii::app()->createAbsoluteUrl('site/index', array(), 'https');
回答by Harikrishnan
Edit .htaccessfile in your project folder and add these lines.It will Redirect all http traffic to https.
编辑.htaccess项目文件夹中的文件并添加这些行。它将所有 http 流量重定向到 https。
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mydomainname.com/ [R,L]
回答by Mayur Bhamre
Try to change host
尝试换主机
'components' => array( ... 'request' => array( 'HostInfo' => 'https://mydomainname.com', ), ... ),
'components' => array( ... 'request' => array( 'HostInfo' => ' https://mydomainname.com', ), ... ),
回答by Radu Dumbr?veanu
The "single shot" way is to set https://in the baseUrlparameter from the configuration:
“单拍”的方法是设置https://在baseUrl从配置参数:
...
'components' => array(
...
'request' => array(
'baseUrl' => ' https://mydomainname.com/site',
),
...
),
...
'components' => array(
...
'request' => array(
'baseUrl' => ' https://mydomainname.com/site',
),
...
),
回答by Jason Axelson
You're best off creating a custom UrlManager implementation as described here:
您最好按照此处所述创建自定义 UrlManager 实现:
http://www.yiiframework.com/wiki/407/url-management-for-websites-with-secure-and-nonsecure-pages
http://www.yiiframework.com/wiki/407/url-management-for-websites-with-secure-and-nonsecure-pages
The benefit is that your users won't have to suffer through needless double redirects every time you have a genuine redirect.
好处是您的用户不必在每次真正重定向时遭受不必要的双重重定向。

