use*_*eve 61 iis http https redirect 301-redirect
我们希望我们的网络服务器 (IIS 10) 上的所有站点都强制执行 SSL(即将 HTTP 重定向到 HTTPS)。
我们目前正在每个站点上“要求 SSL”,并设置一个403 error
处理程序来执行302 redirect
该特定站点的 https 地址。
这很好用。但是对于每个站点来说都是痛苦的,人为错误的空间很大。
理想情况下,我想建立一个永久301 redirect
所有HTTP://*
以HTTPS://*
在 IIS 中是否有一种简单的方法可以做到这一点?
sip*_*ear 94
IIS7+ 的 IIS URL 重写模块 2.1 可能是您的朋友。该模块可以从IIS URL Rewrite下载。使用 URL 重写模块和URL 重写模块 2.0 配置参考解释了如何使用该模块。
安装模块后,您可以使用 IIS 管理器创建主机范围的重定向。选择URL Rewrite、Add Rule(s)...和Blank rule。
名称:
重定向到 HTTPS
匹配 URL
请求的 URL: Matches the Pattern
使用: Wildcards
模式: *
忽略大小写:选中
条件
逻辑分组: Match Any
条件输入:{HTTPS}
检查输入字符串: Matches the Pattern
模式: OFF
忽略大小写:选中
跨条件跟踪捕获组:未选中
服务器变量
留空。
操作
操作类型: Redirect
重定向 URL: https://{HTTP_HOST}{REQUEST_URI}
附加查询字符串:未选中
重定向类型: Permanent (301)
应用规则并运行 IISReset(或单击 IIS 管理器中的重新启动)
或者,在安装模块后,您可以按如下方式修改 applicationHost.config 文件:
<system.webServer>
<rewrite>
<globalRules>
<rule name="Redirect to HTTPS" enabled="true" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" ignoreCase="true" negate="false" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTPS}" ignoreCase="true" matchType="Pattern" negate="false" pattern="OFF" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" redirectType="Permanent" />
</rule>
</globalRules>
</rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
小智 7
我的研究表明这可能是更好的重定向方式:
<rewrite>
<rules>
<rule name="http to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
147811 次 |
最近记录: |