简体   繁体   中英

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.

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]+)

Testing the pattern for the source URL in IIS7 works fine. The destination URL as below need to maintain the IP followed by /product which is R:1 and /582276 which is 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

However the above does not work when using the browser and instead getting an annoying 404.

My web.config looks something like

`

        <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). The url attribute of match element must start with "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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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