IIS Rewrite Rule in web.config to redirect HTTPS requests to HTTP

后端 未结 2 1855
忘了有多久
忘了有多久 2020-12-17 01:14

I need to redirect all https requests to http, for example, if someone visits https://www.example.com/another-page/ to http://www.example.com/another-page/

I have th

相关标签:
2条回答
  • 2020-12-17 01:35

    I set up your rule, cleaned up a little, and it worked; so this isn't really answering with much new.

    Suggestion: Remove the onepage input condition just for testing, as cheesmacfly suggested in the question comment.

    Also, try changing the action to {R:1} instead of {R:0}. It shouldn't matter in this case, but I just like using 1 and up, to match the specific capturing group. R:0 means the entire matched string, which always confuses me just a little.

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

    One possibility is that your browser has cached a previous attempt of your rules. When the redirectType is Permanent, and you're still developing or testing, the browser often caches a previous rule. Clear your browser cache, and/or remove the Permanent, and/or browse in incognito mode. When done testing, change it to permanent. See number 2 and 3 in this answer: https://stackoverflow.com/a/9204355/292060

    0 讨论(0)
  • 2020-12-17 01:50

    Please paste the below code in web.config file.

    <rule name="Redirect to http" stopProcessing="true">
        <match url="(.*)" />
        <conditions>
            <add input="{HTTP}" pattern="off" ignoreCase="true" />
        </conditions>
        <action type="Redirect" url="http://{HTTPS_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
    </rule>
    
    0 讨论(0)
提交回复
热议问题