本文介绍了在 Yii2 上强制使用 HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!
问题描述
要求
如何在 Yii2 上强制重定向到 https(如果用户访问 http 则重定向)?我已经尝试过 web.config 强制使用 https,但它没有用.
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.
场景
我使用的是在 IIS 7.5 上托管的 Yii2 高级应用.
I am using Yii2 advanced app hosted on IIS 7.5.
推荐答案
在 IIS 上非常简单.可以使用重写模块来解决这个问题.例如,
It's very simple on IIS. Can use rewrite module to solve this issue. E.g.,
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<!-- Other stuffs -->
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="Hide Yii Index" stopProcessing="true">
<match url="." ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>
</rules>
</rewrite>
<!-- Other stuffs -->
</system.webServer>
</configuration>
它非常有效和快速.可以用于我们自己的 CDN url,无需 PHP 代码的帮助.
此代码也可用于 ASP.Net.在这种情况下,删除隐藏 Yii 索引部分.
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.
这篇关于在 Yii2 上强制使用 HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!
The End



大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)