在Azure Web App服务中从https重定向到http

Man*_*rio 1 iis https redirect http azure

我有一个支持HTTP和HTTPS(带有效证书)的网站,但遗憾的是,对于某些外部服务的内部问题,HTTPS配置还没有准备好投入生产.

我想通过IIS(web.config文件)重定向每个https请求到http.

我在官方文档中找到了从http重定向到https而不是反向的代码.所以我试图转换它但IIS实际上没有重定向:

<rule name="Redirect to HTTP" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP}" pattern="^OFF$" />
    </conditions>
    <action type="Redirect" url="http://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
Run Code Online (Sandbox Code Playgroud)

yoa*_*ape 7

Azure App Service网站支持IIS URL重写模块,因此您尝试执行的操作应该可行.我认为你唯一错的就是条件,你为一个Server Variable被叫者添加一个条件HTTP,但是没有HTTP,只有HTTPS哪个是ON或者OFF.有关IIS服务器变量的完整列表,请参阅此处.所以,只需翻转它,而不是检查HTTP是否为OFF(不存在且永远不会为真),检查HTTPS是否为ON

<rule name="Redirect to HTTP" stopProcessing="true">
  <match url="(.*)" />
  <conditions>
    <add input="{HTTPS}" pattern="^ON$" />
  </conditions>
  <action type="Redirect" url="http://{HTTP_HOST}/{R:0}" redirectType="Permanent" />
</rule> 
Run Code Online (Sandbox Code Playgroud)