URL重写ASP.NET 4.0中的子域和目录结构

时间:2012-03-14 15:15:37

标签: asp.net iis-7 url-rewriting

我正在尝试重写/重定向ASP.NET 4.0中的URL

示例:

请求的网址
http://www.domain.com/accounting/blog/post/2009/07/17/Getting-the-most-out-of-your-account-firm.aspx

重写/重定向网址
http://blog.domain.com/post/2009/07/17/Getting-the-most-out-of-your-outplacement-firm.aspx

换句话说,将子域从“www”更改为“blog”,并从目录结构中删除“/ accounting / blog”,然后重定向。

以下是我使用的规则(在IIS中传递模式匹配测试,但不起作用):

<rewrite>
<rules>
    <rule name="blog redirect" stopProcessing="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAll">
            <add input="{HTTP_HOST}" pattern="www\.domain\.com\/accounting\/blog\/(.*)" />
        </conditions>
        <action type="Redirect" url="http://blog.domain.com/{C:1}" />
    </rule>
</rules></rewrite>

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

这适用于任何域:

<rules>
    <rule name="blog redirect" stopProcessing="true">
        <match url="^accounting/blog/(.*)" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
            <add input="{HTTP_HOST}" pattern="^www\.(.*)" />
        </conditions>
        <action type="Redirect" url="http://blog.{C:1}/{R:1}" />
    </rule>
</rules>