0
<rewrite>
  <rules>
   <rule name="HTTP to HTTPS redirect" enabled="true" stopProcessing="true">
       <match url="(.*)" ignoreCase="true" />
         <conditions>
          <add input="{HTTPS}" pattern="OFF" />
         </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
         </rule>
      </rules>
  </rewrite>

I have used above url rewrite rule in my web.config file to enable SSL for the whole site. Now I need to change the above rule to filter 2 urls which should work as http. Let's say those urls as https://www.domain.com/owner/Marketing and https://www.domain.com/owner/getinfo. Currently those urls are https hence above rules.So how can I change above rule to filter above 2 urls (i.e. http://www.domain.com/owner/Marketing and http://www.domain.com/owner/getinfo )?

Sampath
  • 63,341
  • 64
  • 307
  • 441

1 Answers1

1

I would add a separate rule to exclude urls that should not be redirected to https.

I cannot test it right now, as I don't have an IIS7 by the hand. but give it a try:

<rewrite>
  <rules>
    <rule name="Skip HTTPs" enabled="true" stopProcessing="true">
      <match url="^(Marketing|getinfo)" ignoreCase="true" />
      <conditions>
        <add input="{HTTPS}" pattern="OFF" />
      </conditions>
      <action type="None" />
    </rule>
    <rule name="HTTP to HTTPS redirect" enabled="true" stopProcessing="true">
      <match url="(.*)" ignoreCase="true" />
      <conditions>
        <add input="{HTTPS}" pattern="OFF" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
    </rule>
  </rules>
</rewrite>

Note that you have to put that file into /owner/ directory as per your example.

you may have seen the documentation on that already - just pointing it out where i found it:

http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

Also here is a maybe-duplicate of that question using lookahead regex rules: Rewriting URLs in IIS7

Community
  • 1
  • 1
Andy P
  • 306
  • 4
  • 10
  • Which file you have mentioned here ('Note that you have to put that file into /owner/ directory as per your example.') ? I got above rule from my web.config file.If I put your code there it should work Know ? Am I right ? – Sampath Feb 24 '14 at 10:08
  • yes. the web.config file needs to be put in that subdirectory. If (e.g.) you have put it onto the root directory of domain.com you may have to change the matching url to include the "owner/" directy as well. see: http://stackoverflow.com/questions/10999735/iis-7-url-rewrite-match-url – Andy P Feb 24 '14 at 10:26
  • Can you put the single match url for both cases ?I mean filter the 2 not match with the all others by using reg-expression ? B'cos I don't think above will work.What will happen when 2nd rule applies.Will it overwrite the first rule or what ? – Sampath Feb 24 '14 at 12:09
  • from my understanding, the first rule applies and due to stopprocessing it ends there. here an discussion: http://webmasters.stackexchange.com/questions/10241/url-rewrite-http-to-https-except-files-in-a-specific-subfolder you can try a single rule usinga lookahead method as well: (but I can't test this one now) also I just found another nice solution, have a look here: http://stackoverflow.com/questions/13320614/iis-url-rewrite-role-except-some-urls – Andy P Feb 24 '14 at 13:46
  • Yep,Its nice url. I applied your method just for the time being.I'll let you know the result tomorrow.Thanks for your support. :) – Sampath Feb 24 '14 at 14:11