6

I am trying to force all traffic on my web site to use HTTPS, using the URL Rewrite 2.0 module added to IIS 7.5. I got that working and now have a need to exclude a couple of pages from using SSL. So I need a rule to rewrite all URL except those referencing this folder to HTTPS. I've been banging my head against the wall on this and am hoping someone can help. I tried creating a rule to match all URL except those in a nossl subfolder as in this example:

<rule name="HTTP to HTTPS redirect" enabled="true" stopProcessing="true">
  <match url="(/nossl/.*)" negate="true" />
  <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTPS}" pattern="off" />
  </conditions>
  <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
</rule>

But this doesn't work. Can anyone help?

migrated from serverfault.com Mar 8 '11 at 0:02

This question came from our site for system and network administrators.

9

If anyone is curious I resolved this problem with the following syntax:

<rule name="NoSSL - folder" enabled="true" stopProcessing="true">
   <match url="^nossl/.*" />
   <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
   </conditions>
   <action type="None" />
</rule>
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTPS}" pattern="off" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
</rule>
  • Brett, I was looking for this exact thing, so thanks! However it appears that this doesn't work if the user browsing the site is using anything but IE. Did you run into this and if so what was your resolution? Thanks – user16526 Jun 25 '12 at 12:36
  • Seth, this has worked perfectly for us for over a year now. We have seen no issues with any browsers. We are running IIS 7.5 on Server 2008 R2. – BrettRobi Jun 25 '12 at 15:51
2

Although I'm a bit late to the party, I would like to suggest this syntax, which is a bit shorter (and IMHO cleaner) than the accepted one:

<rule name="Redirect to HTTPS except /nossl/ folder" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{REWRITE_URI}" url="^nossl/.*" negate="true" />
        <add input="{HTTPS}" pattern="off" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
</rule>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.