简体   繁体   English

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

[英]Redirect using Rewrite module IIS7

I've been following the steps of the below article from IIS resources in order to setup a permanent redirect using the rewrite module 2.0 on IIS7 using a pattern to capture the source URL and serve the destination based on the below regular expressions. 我一直在从IIS资源中遵循以下文章的步骤,以便在IIS7上使用重写模块2.0使用基于以下正则表达式的模式捕获源URL并提供目标,以设置永久重定向。

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

Source (OLD) URL: http://xx.xx.xxx.xx/term/product/term-term/category/example-123/58276 Pattern: http://xx.xx.xxx.xx/term/([az]+)/([az-]+)/([az]+)/([0-9a-z-]+)/([0-9]+) 源(旧)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] +)

Testing the pattern for the source URL in IIS7 works fine. 在IIS7中测试源URL的模式可以正常工作。 The destination URL as below need to maintain the IP followed by /product which is R:1 and /582276 which is R:5 如下所示的目标URL需要维护IP,后跟是/ product的R:1和/ 582276这是R:5

Destination URL: http://xx.xx.xxx.xx/ {R:1}/{R:5} Therefore the actual destination (NEW) URL is http://xx.xx.xxx.xx/product/58276 目标网址: http://xx.xx.xxx.xx/ {R:1} / {R:5}因此,实际的目标(NEW)URL为http://xx.xx.xxx.xx/product/58276

However the above does not work when using the browser and instead getting an annoying 404. 但是,当使用浏览器并获取烦人的404时,上述方法不起作用。

My web.config looks something like 我的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" />

` `

Any Ideas? 有任何想法吗?

Thanks 谢谢

The input value for pattern matching is a path part of the URL excluding leading / (forward slash). 模式匹配的输入值是URL的路径部分,不包括前导/ (正斜杠)。 The url attribute of match element must start with "term": match元素的url属性必须以“ term”开头:

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

If you want to make sure the rule is applied only to xx.xx.xxx.xx host requests, add condition: 如果要确保该规则仅适用于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