I do redirect users from Http
to Https
by below configuration
<rewrite>
<rules>
<rule name="HTTP_TO_HTTPS" enabled="true" stopProcessing="true">
<match url="(.*)"/>
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="^OFF$"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false"/>
</rule>
</rules>
</rewrite>
it works as expected. But here is a problem that it only redirects to Https
but not excepted origin. I mean
http://www.example.com
to https://www.example.com
http://example.com
to https://example.com
The above situation cause, users have different origins that the Cross-origin resource sharing (CORS) policy
problem.
I want to redirect all users to https://example.com
in order to avoid conflicted origins.
You could use the rewrite module to remove the WWW part also
<rule name="Remove www" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www" />
</conditions>
<action type="Redirect" url="http://example.com/{R:0}" redirectType="Permanent" />
</rule>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With