Yii2将所有URL重定向到https://www 不使用htaccess

Yii2将所有URL重定向到https://www 不使用htaccess,yii2,Yii2,我需要能够重定向到Yii2中的所有URL(非www和www) 我想尝试在不使用.htaccess的情况下执行此操作 通过组件中的urlManager创建URL不是问题: urlManager => [ 'baseUrl' => 'https://www.somesite.com' ] 然而,我正在努力做重定向。我确实看过这篇文章——这对Yii2有帮助吗 编辑 我在下面的评论中提到,当我在backend folder index.php中添加$_SERVER['HTTPS']

我需要能够重定向到Yii2中的所有URL(非www和www)

我想尝试在不使用.htaccess的情况下执行此操作

通过组件中的urlManager创建URL不是问题:

urlManager => [
    'baseUrl' => 'https://www.somesite.com'
]
然而,我正在努力做重定向。我确实看过这篇文章——这对Yii2有帮助吗

编辑

我在下面的评论中提到,当我在backend folder index.php中添加$_SERVER['HTTPS']='on'时,我不需要对.htaccess文件做任何事情就可以获得SSL,这很好。这在\yii2\web\Request.php中的函数getIsSecureConnection()中使用

本文引用了这一点

但是,如果我对frontendex.php文件执行相同的操作,则不会得到相同的行为

比如说

=>

(我目前在此域上没有SSL!)

=>

非常感谢任何帮助

您可以使用Apache而不使用.htaccess
You can do it with Apache without .htaccess
#
# Non www 
#
<VirtualHost *:80>
    ServerName example.com
    # Other alternatives domains:
    ServerAlias example.net www.example.net
    ServerAlias example.org www.example.org

    RedirectPermanent / http://www.example.com/
</VirtualHost>


#
# Main site - www
#
<VirtualHost *:80>
    ServerName www.example.com

    DocumentRoot /var/www/example.com/frontend/web
    # ...
</VirtualHost>
# #非www # ServerName example.com #其他备选领域: ServerAlias example.net www.example.net ServerAlias example.org www.example.org 重定向永久/http://www.example.com/ # #主网站-www # 服务器名www.example.com DocumentRoot/var/www/example.com/frontend/web # ...
我找到了这个解决方案,这正是我在Yi2上需要的

,扩展Yii应用程序类


所有的功劳都归于Hi的可能副本,我知道有很多htaccess重定向问题-我想针对Yii2,而不必使用。htaccess在所有Hi中,我使用的是高级模板。在后端,我刚刚在index.php文件中添加了$_SERVER['HTTPS']='on'。成功了!然而,在前端,做同样的事情并不会产生同样的结果。非常感谢这一点-然而,我想直接用Yii2做它-现在就有解决方案了