Redirect from https to http in Azure Web App service

﹥>﹥吖頭↗ 提交于 2020-01-15 09:23:07

问题


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.

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

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>

回答1:


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://stackoverflow.com/questions/42046083/redirect-from-https-to-http-in-azure-web-app-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!