我想使用web.config重写规则在http Azure应用服务中启用http重定向。根据我所能找到的所有文档,使用重写规则的Web配置重定向是获得此功能的官方方式。我喜欢并希望支持的功能之一是gzip作为Accepted-Encoding,这是默认启用的。但是这两个功能似乎有冲突。是否有另一种方法来做重定向?我必须禁用压缩吗?Azure Http to Https重定向不适用于SPA
这里是我的重定向规则:
<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>
curl命令与我只想通过SSL进行传输的内容进行响应:
执行如预期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以外的请求似乎按预期工作。只有root 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>
我能够重新创建该问题。我打开支持票: 1)创建一个天蓝色的网站 2)从我更新的帖子中添加web.config(将index.html更改为该网站的默认文件) 3)在浏览器中加载您的网站将被重定向) 4)加载您的网站在第二个浏览器(你不会被重定向) 5)如果你添加任何东西到网址的末尾,你将被重定向。 –