4

Currently, on my Production server, i have Inbound Rule set as follows which works file for all my requirements.

Inbound Rule is as follows.

Match URL section
Requested URL: Matches the Pattern
Using: Regular Expression
Pattern: (.*)
Ignore Case: checked.

Conditions section
Logical grouping: Match All.
Input: {HTTPS}
Type: Matches the Pattern
Pattern: ^OFF$
Track capture groups across conditions: unchecked.

Action section:
Action type: Redirect
Redirect URL: https://www.domainname.com/{R:0}
Append query string: checked.
Redirect Type: Permanent (301).

My Requirement is: When user types

https://beta.domain.com it should redirect to https://www.domain.com. 

if user types

http://beta.domain.com it should redirect to https://www.domain.com. 

If user types

http://www.domain.com it should redirect to https://www.domain.com

If user types

http://domain.com it should redirect to https://www.domain.com

Thanks in advance. Any help would be appreciated.

Thanks in advance.

shakti
  • 191
  • 1
  • 8
  • 21

1 Answers1

3

Isn't that exactly what the conditional is suppose to do? It checks whether HTTPS is OFF and only then the redirect will happen. If HTTPS is ON it is not suppose to redirect otherwise you will end up in an endless redirect.

If you always want the hostname to be www.domainname.com you should add that as an additional conditional. E.g.:

<rule name="Force HTTPS and host name: www.domainname.com" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTPS}" negate="true" pattern="^ON$" />
        <add input="{HTTP_HOST}" negate="true" pattern="^www\.domainname\.com$" />
    </conditions>
    <action type="Redirect" url="https://www.domainname.com/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>

If either HTTPS is not ON or HTTP_HOST is not www.domainname.com it will redirect. Only if both are true, it will not redirect.

Marco Miltenburg
  • 6,123
  • 1
  • 29
  • 29
  • Thanks Marco, I added your help!!!. But it was not satisfying my requirement. Please once check my requirement in my Main Question. I have updated the Requirement section with more clarity. Thanks in advance. – shakti May 28 '12 at 05:56
  • I think it fulfills all your requirements except for your first but that's due to the nature of HTTPS. Your first requirement can only work if your SSL certificate is a wildcard certificate for `*.domainname.com` or if it's a multi domain certificate for both `www.domainname.com` and `beta.domainname.com`. If your certificate is only valid for `www.domainname.com` it will cause browsers to show a security warning when you open `https://beta.domainname.com`. There's nothing you or IIS can do about that. – Marco Miltenburg May 29 '12 at 10:45