【问题标题】:Redirect using Rewrite module IIS7使用重写模块 IIS7 重定向
【发布时间】:2012-03-25 11:32:48
【问题描述】:

我一直遵循 IIS 资源中以下文章的步骤,以便使用 IIS7 上的重写模块 2.0 设置永久重定向,使用模式捕获源 URL 并根据以下正则表达式提供目标。

http://learn.iis.net/page.aspx/461/creating-rewrite-rules-for-the-url-rewrite-module

来源(旧)网址:http://xx.xx.xxx.xx/term/product/term-term/category/example-123/58276 模式:http://xx.xx.xxx.xx/term/([az]+)/([az-]+)/([az]+)/([0-9a-z-]+)/ ([0-9]+)

在 IIS7 中测试源 URL 的模式可以正常工作。下面的目标 URL 需要维护 IP 后跟 /product 是 R:1 和 /582276 是 R:5

目标网址:http://xx.xx.xxx.xx/{R:1}/{R:5} 因此实际的目标(新)URL 是http://xx.xx.xxx.xx/product/58276

但是,在使用浏览器时上述方法不起作用,而是出现烦人的 404。

我的 web.config 看起来像

`

        <rules>

            <rule name="PatternRedirect" stopProcessing="true">

                <match url="http://xx.xx.xxx.xx/term/([a-z]+)/([a-z-]+)/([a-z]+)/([0-9a-z-]+)/([0-9]+)" />

                <action type="Redirect" url="http://xx.xx.xxx.xx/{R:1}/{R:5}" />

            </rule>

        </rules>

    </rewrite>

    <httpRedirect enabled="true" destination="" exactDestination="true" httpResponseStatus="Permanent" />

`

有什么想法吗?

谢谢

【问题讨论】:

    标签: redirect iis-7 rewrite


    【解决方案1】:

    模式匹配的输入值是 URL 的路径部分,不包括前导 /(正斜杠)。 match元素的url属性必须以“term”开头:

    <match url="term/([a-z]+)/([a-z-]+)/([a-z]+)/([0-9a-z-]+)/([0-9]+)" />
    

    如果要确保规则仅适用于 xx.xx.xxx.xx 主机请求,请添加条件:

    <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^xx.xx.xxx.xx$" />
    </conditions>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-06
      • 2011-01-26
      • 2010-11-06
      • 2012-03-06
      • 2012-03-31
      • 1970-01-01
      • 2011-03-16
      • 2011-03-07
      相关资源
      最近更新 更多