UrlRewriter.net表达式示例

时间:2010-03-18 21:27:04

标签: urlrewriter.net

我需要为下面的每种表达式类型提供一些web.config示例:

$number

最后一个子组字符串与组号相匹配。

$<name>

由名为name的组匹配的最后一个子字符串由(?&lt; name&gt;)匹配。

${property}

评估表达式时的属性值。

${transform(value)}

调用指定值的转换结果。

${map:value}

使用地图映射指定值的结果。如果不存在映射,则替换为空字符串。

${map:value|default}

使用地图映射指定值的结果。如果不存在映射,则替换为默认值。

示例:

<rewriter>
    <if url="/tags/(.+)" rewrite="/tagcloud.aspx?tag=$1" />
    <!-- same thing as <rewrite url="/tags/(.+)" to="/tagcloud.aspx?tag=$1" /> -->
</rewriter>

非常感谢!

1 个答案:

答案 0 :(得分:1)

这是我发现/猜到的。未经测试。

$ number:http://urlrewriter.net/index.php/support/using

<rewrite url="^(.*)/(\?.+)?$" to="$1/default.aspx$2?" />

$1 matches (.*)
$2 matches (\?.+)

$&LT;名称&gt; :这个我在正则表达式上不太确定,在文档中找不到任何东西

<rewrite url="^(?<group1>(.*))/(\?.+)?$" to="$<group1>/default.aspx$2?" />

$<group1> matches 

$ {property}:http://urlrewriter.net/index.php/support/reference/actions/set-property

<set property="branch" value="$3" />
<rewrite to="/showbranch.aspx?branch=${branch}" />

$ {transform(value)}:http://urlrewriter.net/index.php/support/reference/transforms

<set property="transform-name" value="lower" />
<set property="value-to-transform" value="THIS WAS UPPER CASE" />

<redirect to="/WebForm1.aspx?q=${encode(${${transform-name}(${value-to-transform})})}" />

results in "/WebForm1.aspx?q=this+was+upper+case"

$ {map:value}:http://urlrewriter.net/index.php/support/reference/transforms/static

<mapping name="areas">
    <map from="sydney" to="1" />
    <map from="melbourne" to="2" />
    <map from="brisbane" to="3" />
</mapping>

<rewrite to="/area.aspx?area=${areas:$3}" />

results in "/area.aspx?area=brisbane"

$ {地图:值|默认}

<mapping name="areas">
    <map from="sydney" to="1" />
    <map from="melbourne" to="2" />
    <map from="brisbane" to="3" />
</mapping>

<rewrite to="/area.aspx?area=${areas:$4|perth}" />

results in "/area.aspx?area=perth"