使用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以包含通配符网址,因此我有一个add
元素与以下网址匹配:
/products/id/1
/products/id/2
/products/id/3
/products/id/4
这样的事情可能吗?
答案 0 :(得分:0)
我通过向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>