简体   繁体   中英

IIS URL rewrite rule for https and containing path

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM