2

I'm trying to figure out a url rewrite rule to rewrite http requests into https only when a specific path is accessed like below. I've tried quite a few things that in the test pattern seem as though they should work but it never does.

url accessed: http://example.com/books/test.css

I need to check for the http:// and /books/ to form the proper url below.

url needed: https://example.com/books/test.css

A request of http://example.com/book/test.css should be ignored.

Andrew S
  • 126
  • 1
  • 8

1 Answers1

5

You can specify the patten in the <match> element :

<rule name="Force HTTPS for /books/" enabled="true">
    <match url="^/books/.*$" ignoreCase="false" />
    <conditions>
        <add input="{HTTPS}" pattern="off" />
    </conditions>
    <action type="Redirect" redirectType="Permanent"
            url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="true"  />
</rule>

or by adding a new <condition>

<rule name="Force HTTPS for /books/" enabled="true">
    <match url="(.*)" ignoreCase="false" />
    <conditions>
        <add input="{HTTPS}" pattern="off" />
        <add input="{REQUEST_URI}" pattern="^/books/.*$" />
    </conditions>
    <action type="Redirect" redirectType="Permanent"
            url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="true"  />
</rule>
Cyril Durand
  • 15,834
  • 5
  • 54
  • 62
  • thanks for this. I opted for the 2nd option. Only thing I had to add was an equal sign after pattern in this line – Andrew S Jun 03 '15 at 20:01
  • what is the meaning of `` ? i am unaware of iis rewrite rule and that why i asked here – Thomas Nov 24 '17 at 08:56