In trying to redirect http traffic to https, I have found the two following rules, which seem to be doing the same thing, however they have small differences in two places. Should I prefer the one over the other ? Is there any benefit of any sort ? (performance, corner cases etc.)
rule1:
<rule name="HTTP to HTTPS Redirect" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{SERVER_PORT_SECURE}" pattern="^0$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
rule 2:
<rule name="HTTP to HTTPS Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"
redirectType="Permanent" />
</rule>
the differences are in the input and in the redirected url where one uses {R:1} and the other REQUEST_URI.
Thank you in advance
Both rules give the same result. And there is no significant difference in performance between them. Besides IIS caches such rules at kernel level by default. This means that the requests will most likely be responded from HTTP Kernel-Mode Driver, without reaching the web application. So these rules will work as fast as you can't measure the difference.
Yet, if you like to do unnecessary optimizations (lik I do sometimes :$) check the following rule out.
Here are the unnecessarily intended improvements with this rule;
ignoreCase="false"
) is cheaper.0
for{SERVER_PORT_SECURE}
is cheaper than lookingoff
for{HTTPS}
.