2

使用 IIS Url Rewrite,是否可以使用 RewriteMaps 匹配通配符 URL?例如,我有以下重写规则:

<rule name="Disable access except for RewriteMap URLs" enabled="true" stopProcessing="true">
    <conditions>
        <add input="{Allowed Urls:{URL}}" pattern="1" negate="true" />
    </conditions>
    <match url="(.*)" />
    <action type="Redirect" url="http://{HTTP_HOST}" />
</rule>

它使用以下 RewriteMap:

<rewriteMap name="Allowed Urls">
    <add key="/products" value="1" />
    <add key="/products/product-1" value="1" />
    <add key="/products/product-2" value="1" />
</rewriteMap>

我想修改我的 RewriteMap 以包含通配符 URL,因此我有一个add与以下 URL 匹配的元素:

/products/id/1
/products/id/2
/products/id/3
/products/id/4

这样的事情可能吗?

4

1 回答 1

1

我通过向我的 RewriteRule 添加附加条件来解决此问题,如下所示:

<rule name="Disable access except for RewriteMap URLs" enabled="true" stopProcessing="true">
    <conditions>
        <add input="{Allowed Urls:{URL}}" pattern="1" negate="true" />
        <add input="{REQUEST_URI}" negate="true" pattern="^/products/id/(.*)" ignoreCase="true" />
    </conditions>
    <match url="(.*)" />
    <action type="Redirect" url="http://{HTTP_HOST}" />
</rule>
于 2015-12-03T10:13:35.240 回答