url rewriting - Combination of IIS rewrite rules - redirect to changed domain name, remove hostname prefix redirect to ssl -
my iis website accessed http://mywebsite.com , have 3 objectives related url rewriting:
- redirect website's new name, mynewwebsite.com
- remove www prefix if exists (eg www.mywebsite.com -> mywebsite.com or www.mynewwebsite.com --> mynewwebsite.com
- redirect ssl
so in summary want redirect inbound requests https://mynewwebsite.com/anything*.
the input cases must accounted 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 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 rule set following input case failing (the www isn't stripped): https://www.mynewwebsite.com/anything*
i've banged head against sufficiently question fundamental understanding of how rule definitions work.
- anything present or not exist @ all
i arrived @ following rules work, afraid coincidence rather me understanding what's happening. comments welcome.
<rewrite> <rules> <rule name =" force https" enabled="true"> <match url =" (.*)" ignorecase= "false " /> <conditions logicalgrouping =" matchany" > <add input =" {http_host}" negate="true" pattern =" ^mynewwebsite\.com$" /> <add input =" {https}" pattern= "^www.mynewwebsite\.com$ " /> </conditions> <action type =" redirect" url= "https://mynewwebsite.fm/{r:1} " appendquerystring="true" redirecttype =" permanent" /> </rule> </rules> </rewrite>
Comments
Post a Comment