【发布时间】:2017-08-29 19:28:08
【问题描述】:
我正在尝试使用 web.config 重写规则在我们的 Azure 应用服务中启用 http 到 https 重定向。根据我能找到的所有文档,使用重写规则的 Web 配置重定向是获得此功能的官方方式。我喜欢并希望支持的功能之一是 gzip 作为 Accepted-Encoding,这是默认启用的。但这两个特征似乎有冲突。还有另一种方法来进行重定向吗?我必须禁用压缩吗?
这是我的重定向规则:
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)"/>
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="Off"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" appendQueryString="true" />
</rule>
使用我只想通过 SSL 传递的内容响应的 Curl 命令:
curl "http://[MyUrl]/" -H "Accept-Encoding: gzip, deflate" --compressed
按预期执行的Curl命令:
curl "http://[MyUrl]/"
回复:
HTTP/1.1 301 Moved Permanently
Content-Length: 154
Content-Type: text/html; charset=UTF-8
Location: https://[MyUrl]/
Server: Microsoft-IIS/8.0
X-Powered-By: ASP.NET
Date: Tue, 29 Aug 2017 19:29:29 GMT
提前致谢。
如果这很有价值,根 url 之外的请求似乎可以按预期工作。只有根 url 似乎返回没有重定向的内容。
更新
我认为这可能与我的 SPA 重写规则有关,尽管我不确定干扰,因为第一条规则对其进行了 stopProcessing。我能够在 cdwredirecttest.azurewebsites.net 上重新创建该问题。如果您点击该站点,它会将您重定向到 https,但只是第一次。打开另一个浏览器并重试,这一次它将通过 http 加载站点。在服务器缓存 gzip 响应后,您将不再被重定向。这是我的完整 web.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to https" stopProcessing="true">
<match url="^(.*)$" ignoreCase="true" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="Off" ignoreCase="true"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" appendQueryString="true" />
</rule>
<rule name="Redirect all requests">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="index.html" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
【问题讨论】:
标签: azure ssl iis single-page-application azure-web-app-service