1
votes

I have this rewrite rule in web.config on our Azure app to ensure the users always use HTTPS:

           <rule name="HTTP to HTTPS redirect"
                  stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}"
                         pattern="off" />
                    <add input="{REQUEST_URI}"
                         pattern="^clientaccesspolicy\.xml$"
                         negate="true" />
                    <add input="{REQUEST_URI}"
                         pattern="^crossdomain\.xml$"
                         negate="true" />
                </conditions>
                <action type="Redirect"
                        redirectType="Found"
                        url="https://{HTTP_HOST}/{R:1}" />
            </rule>

It works fine. The users always hit the site using a subdomain of our company URL and we have a wildcard certificate.

But when the app is staging I would like to use it without https (but still not allow http acccess to the standard cloudapp subdomain). so for example this would work over http:

http://f9eccd6a9a044270b5ce97ae614c9ee1.cloudapp.net

But this wouldn't:

http://myazuresubdomain.cloudapp.net

My Regex skills are minimal and my url rewrite skils are limited to copying the above from SO. So could someone help me with the rule that will help me acheive the above? Perhaps a negate for a url that has exactly 32 chracters then .cloudapp.net?

Thanks

Mark

1

1 Answers

2
votes

The following rule should match what you're after. Placing it first will skip the https redirect due to the 'stopProcessing' attribute.

<rule name="Staging CloudApp" stopProcessing="true">
   <match url=".*" />
   <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
      <add input="{HTTP_HOST}" pattern="([0-9a-f]{32})\.cloudapp\.net" />
   </conditions>
   <action type="None" />
</rule>