【问题标题】:IIS Url Rewrite Maps & Wildcard URLsIIS URL 重写映射和通配符 URL
【发布时间】:2016-03-07 19:50:00
【问题描述】:

使用 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,这样我就有一个与以下 URL 匹配的 add 元素:

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

这样的事情可能吗?

【问题讨论】:

    标签: iis url-rewriting url-rewrite-module rewritemap


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 2013-06-01
      • 2011-06-18
      • 2014-02-19
      • 1970-01-01
      • 2012-08-11
      • 2014-04-16
      • 2011-11-19
      • 2020-03-14
      • 1970-01-01
      相关资源
      最近更新 更多