【发布时间】:2021-01-29 15:31:17
【问题描述】:
我有一个关于 SSL 的小问题。我有一个网站,我们购买了 SSL 并在 web.config 中制定了一些重写规则。但问题是,有时我们无法重定向到 https 版本。当我们使用 https 键入域时,它可以正常工作,但是当我们删除 https 时,我们无法重定向到该站点的安全版本。这是我们的 web.config 文件(为了隐私,我将我们的站点名称挂为 example.com);
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to www" enabled="false" stopProcessing="true">
<match url="(.*)" />
<conditions trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^example.COM$" />
</conditions>
<action type="Redirect" url="{MapProtocol:{HTTPS}}://www.example.com/{R:1}" />
</rule>
<rule name="AngularJS Routes" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" logRewrittenUrl="false" />
</rule>
<rule name="Redirect HTTP to HTTPS" enabled="false" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{HTTP_URL}" appendQueryString="false" redirectType="SeeOther" />
</rule>
<rule name="Force non-WWW and SSL" enabled="true" stopProcessing="true">
<match url="(.*)" negate="true" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://example.com/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
我们还可以做些什么来确保每次都重定向到安全版本 (https) 的链接?
【问题讨论】:
标签: security ssl web-config websecurity