0

As simple as it sounds and as much as I've searched, I'm not able to get

http://example.com/subfolder to redirect to https://example.com/subfolder using IIS rewrite.

Note: This is only when "http" is explicitly stated in the browser.

<rule name="HTTP to HTTPS redirect" stopProcessing="true">
                <match url="(.*)" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{HTTPS}" pattern="off" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Found" />enter code here

Thanks!

  • possible duplicate of [asp.net c# redirecting from http to https](http://stackoverflow.com/questions/5305443/asp-net-c-sharp-redirecting-from-http-to-https) – Ormoz Aug 22 '15 at 03:02

1 Answers1

0

The problem with your rule is that REQUEST_URI in your redirect action is the whole URI as requested. What you want is the result of the rule match. R1 will give you this. This answer gives a good explanation of the rule back-references. A working rule can be constructed like this:

<rewrite>
  <rules>
    <rule name="HTTP to HTTPS Redirect" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
      <add input="{HTTPS}" pattern="off" ignoreCase="true" />
    </conditions>
    <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
    </rule>
  </rules>
</rewrite>
Community
  • 1
  • 1
jltrem
  • 12,124
  • 4
  • 40
  • 50