gpt4 book ai didi

Azure Http 到 Https 重定向不适用于 SPA

转载 作者:太空宇宙 更新时间:2023-11-03 13:06:01 24 4
gpt4 key购买 nike

我正在尝试使用 web.config 重写规则在我们的 Azure 应用服务中启用 http 到 https 重定向。根据我能找到的所有文档,使用重写规则的 Web 配置重定向是获得此功能的官方方法。我喜欢并希望支持的功能之一是 gzip 作为接受编码,默认情况下启用此功能。但这两个功能似乎是冲突的。还有其他方法可以进行重定向吗?我必须禁用压缩吗?

这是我的重定向规则:

<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

提前致谢。

如果这很有值(value),根 URL 之外的请求似乎可以按预期工作。只有根 url 似乎会返回没有重定向的内容。

更新
我认为这可能与我的 SPA 重写规则有关,尽管我不确定是否存在干扰,因为第一条规则已停止处理。我能够在 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>

最佳答案

根据您的描述,我遵循您的 URL 重写规则并在我的 Azure Web 应用程序上进行了测试。我指定了 -L 选项,以便使 curl 能够遵循 HTTP 重定向,如下所示:

curl "http://{your-webapp}.azurewebsites.net/"-L -H "Accept-Encoding: gzip, deflate"--compressed -v

curl "http://{your-webapp}.azurewebsites.net/home/index"-L -H "Accept-Encoding: gzip, deflate"--compressed -v

我可以从上述命令中检索带有 Content-Encoding: gzip header 的响应,如下所示:

enter image description here

enter image description here

关于Azure Http 到 Https 重定向不适用于 SPA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45946960/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com