Answered by:
Multiple rule with conditions

Question
-
User-60066724 posted
Hi,
I'm not an expert in IIS and I have an issue with the URL Rewrite Module.
I'd like to redirect these following URL :
http://myHostname to httpS://myHostname.myDomain.com
httpS://myHostname to httpS://myHostname.myDomain.com
http://myHostname.myDomain.com to httpS://myHostname.myDomain.com
httpS://myHostname.myDomain.com to the same URLThe same thing when there are parameters :
http://myHostname/myParameters to httpS://myHostname.myDomain.com/myParameters
httpS://myHostname/myParameters to httpS://myHostname.myDomain.com/myParameters
http://myHostname.myDomain.com/myParameters to httpS://myHostname.myDomain.com/myParameters
httpS://myHostname.myDomain.com/myParameters to the same URLActually, I have one rule :
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}.myDomain.com/{R:1}" appendQueryString="false" redirectType="Found" />
</rule>But with this rule, all cases don't work.
Could you help me ?
Thank you in advance for your time,
Kevin
Wednesday, May 24, 2017 11:03 AM
Answers
-
User-460007017 posted
Hi Kevin,
To ensure the rewrite rule could works fine, please check whether the bindings with http://myHostname,httpS://myHostname,http://myHostname.myDomain.com has been created on your IIS server.
Then you could use following rule to achieve the redirect:
<rule name="rewrite all to https" stopProcessing="true"> <match url="(.*)" /> <conditions trackAllCaptures="true"> <add input="{HTTP_HOST}" pattern="(www.jokiesd.com)|myhostname" /> <add input="{HTTPS}" pattern="off" /> <add input="{REQUEST_URI}" pattern="(.*)" /> </conditions> <action type="Redirect" url="https://myHostname.myDomain.com{C:2}" redirectType="Temporary" /> </rule> <rule name="rewrite https" stopProcessing="true"> <match url="(.*)" /> <conditions trackAllCaptures="true"> <add input="{HTTP_HOST}" pattern="myHostname" /> <add input="{HTTPS}" pattern="on" /> <add input="{REQUEST_URI}" pattern="(.*)" /> </conditions> <action type="Redirect" url="https://myHostname.myDomain.com{C:1}" redirectType="Temporary" /> </rule>
To avoid an infinite loop, it is not recommended to enable the redirect URL to itself. So I created two rewrite rule to rewrite the binding with http and the binding with httpS://myHostname.
Remember to place the rule under the website which have the three bindings above.
Best Regards,
yuk Ding
- Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
Thursday, May 25, 2017 2:21 AM
All replies
-
User-460007017 posted
Hi Kevin,
To ensure the rewrite rule could works fine, please check whether the bindings with http://myHostname,httpS://myHostname,http://myHostname.myDomain.com has been created on your IIS server.
Then you could use following rule to achieve the redirect:
<rule name="rewrite all to https" stopProcessing="true"> <match url="(.*)" /> <conditions trackAllCaptures="true"> <add input="{HTTP_HOST}" pattern="(www.jokiesd.com)|myhostname" /> <add input="{HTTPS}" pattern="off" /> <add input="{REQUEST_URI}" pattern="(.*)" /> </conditions> <action type="Redirect" url="https://myHostname.myDomain.com{C:2}" redirectType="Temporary" /> </rule> <rule name="rewrite https" stopProcessing="true"> <match url="(.*)" /> <conditions trackAllCaptures="true"> <add input="{HTTP_HOST}" pattern="myHostname" /> <add input="{HTTPS}" pattern="on" /> <add input="{REQUEST_URI}" pattern="(.*)" /> </conditions> <action type="Redirect" url="https://myHostname.myDomain.com{C:1}" redirectType="Temporary" /> </rule>
To avoid an infinite loop, it is not recommended to enable the redirect URL to itself. So I created two rewrite rule to rewrite the binding with http and the binding with httpS://myHostname.
Remember to place the rule under the website which have the three bindings above.
Best Regards,
yuk Ding
- Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
Thursday, May 25, 2017 2:21 AM -
User-60066724 posted
Thank you for your answer. It helps a lot :-)
Tuesday, May 30, 2017 9:31 AM