I have managed to configure a rewrite rule for my web site using this answer:
<rule name="Redirect from non www" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^example.com$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Permanent" />
</rule>
<!-- this is the rule I am interested in -->
<rule name="Redirect from non https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTP_HOST}" pattern="^www.example.com$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Permanent" />
</rule>
However, I have trouble understanding how url
attribute from action
tag actually works. If I go to IIS -> Rewrite rules -> Redirect from non https -> Test pattern -> enter url http://www.example.com/subdir/?param=value
and hit Test, I receive {R:0}
= http://www.example.com/subdir/?param=value
.
This makes sense, as *
regex expression will match the whole string.
Question: How does URL rewrite engine obtain https://www.example.com/subdir/?param=value
instead of https://www.example.com/http://www.example.com/subdir/?param=value
?