繁体   English   中英

使用重写模块IIS7进行重定向

[英]Redirect using Rewrite module IIS7

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

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

源(旧)URL: 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}因此,实际的目标(NEW)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" />

`

有任何想法吗?

谢谢

模式匹配的输入值是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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM