从https重定向到Azure Web App服务中的http [英] Redirect from https to http in Azure Web App service

查看:73
本文介绍了从https重定向到Azure Web App服务中的http的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个同时支持HTTP和HTTPS(具有有效证书)的网站,但是很遗憾,由于某些外部服务的内部问题,HTTPS配置尚未准备好投入生产.

I have a website which supports both HTTP and HTTPS (with a valid certificate) but unfortunally for internal issues with some external services, the HTTPS configuration is not ready yet to go in production.

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

I would like to redirect for now through IIS (web.config file) every https request to http.

我在官方文档中找到了从http重定向到https的代码,但没有找到相反的代码.因此,我尝试将其转换,但IIS实际上并未重定向:

I found in the official doc, the code to redirect from http to https but not the inverse. So I tried to convert it but IIS does not actually redirect:

<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>

推荐答案

Azure App Service网站支持IIS URL重写模块,因此您尝试执行的操作应该可以进行.我认为您唯一出错的是条件,您正在为称为 HTTP Server Variable 添加条件,但是没有 HTTP ,只有 HTTPS ON OFF .有关IIS服务器变量的完整列表,请参见此.因此,只需将其翻转,而不是检查HTTP是否已关闭(不存在且永远不会为真),而是检查HTTPS是否已打开

Azure App Service websites supports the IIS URL rewrite module so what you are trying to do should work. I think the only thing you got wrong is the conditon, you are adding a condition for a Server Variable called HTTP, but there is no HTTP, only HTTPS which is either ON or OFF. See this for full list of IIS Server Variables. So, just flip it and instead of checking if HTTP is OFF (which doesn't exist and will never be true), check if HTTPS is 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> 

这篇关于从https重定向到Azure Web App服务中的http的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆