My IIS website is currently accessed as http://mywebsite.com and I have 3 objectives related to url rewriting:
- Redirect to the website's new name, mynewwebsite.com
- Remove www prefix if it exists (eg www.mywebsite.com -> mywebsite.com or www.mynewwebsite.com --> mynewwebsite.com
- Redirect to SSL
So in summary I want to redirect all inbound requests to https://mynewwebsite.com/anything*.
The input cases that must be accounted for are
- http://mynewwebsite.com/anything*
- http://www.mynewwebsite.com/anything*
- http://mywebsite.com/anything*
- http://www.mywebsite.com/anything*
- https://mywebsite.com/anything*
- https://www.mywebsite.com/anything*
- https://www.mynewwebsite.com/anything*
My rewrite rules look as follows:
<rewrite>
<rules>
<rule name="Do stuff" enabled="true">
<match url="(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="mywebsite.com" />
<add input="{HTTPS}" pattern="^www.mynewwebsite\.com$" />
</conditions>
<action type="Redirect" url="https://mynewwebsite.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
With this rule set the following input case is failing (the www isn't stripped): https://www.mynewwebsite.com/anything*
I've banged my head against this sufficiently that I question my fundamental understanding of how rule definitions work.
- anything could be present or not exist at all