简体   繁体   English

https的IIS URL重写规则并包含路径

[英]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. 我试图找出一个URL重写规则,以仅在访问特定路径(如下所示)时将http请求重写为https。 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 访问的网址: http : //example.com/books/test.css

I need to check for the http:// and /books/ to form the proper url below. 我需要检查http://和/ books /以便在下面形成正确的网址。

url needed: https://example.com/books/test.css 所需网址: https//example.com/books/test.css

A request of http://example.com/book/test.css should be ignored. 应该忽略http://example.com/book/test.css的请求。

You can specify the patten in the <match> element : 您可以在<match>元素中指定样式:

<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> 或添加新的<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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