To augment LazyOne's answer, here is an annotated version of the answer.
<rewrite>
<rules>
<clear />
<rule name="Redirect all requests to https" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action
type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}"
redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
Clear all the other rules that might already been defined on this server. Create a new rule, that we will name "Redirect all requests to https". After processing this rule, do not process any more rules! Match all incoming URLs. Then check whether all of these other conditions are true: HTTPS is turned OFF. Well, that's only one condition (but make sure it's true). If it is, send a 301 Permanent redirect back to the client at http://www.foobar.com/whatever?else=the#url-contains
. Don't add the query string at the end of that, because it would duplicate the query string!
This is what the properties, attributes, and some of the values mean.
MatchAll
) or any of the conditions must be true (MatchAny
); similar to AND vs OR. match
and its conditions
are all true.
redirect
(client-side) or rewrite
(server-side). https://
with two server variables.url
or not; in this case, we are setting it to false, because the {REQUEST_URI}
already includes it.The server variables are
{HTTPS}
which is either OFF
or ON
. {HTTP_HOST}
is www.mysite.com
, and {REQUEST_URI}
includes the rest of the URI, e.g. /home?key=value
#fragment
(see comment from LazyOne).See also: https://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference