简体   繁体   中英

web.config Redirect Rule - Match URL

This seems to be a pretty straight forward change, however it's not matching the URL and none of the answers on stackoverflow seem to address this simple use of redirect rules. I believe it has something to do with the '?id=XXXX' portion of the URL.

We have some old versions of pages, which I am trying to add redirects to the new version of the pages.

Here's an example of my rules:

<rule name="old_Page" stopProcessing="true">
    <match url="^Page.aspx?id=12345"/>
    <action type="Redirect" url="http://www.example.com/newPage.aspx"    redirectType="Permanent" />
</rule>

Any help would be most appreciated.

I used a different method to create Static Redirects in the web.config from this article:

https://www.iis.net/learn/extensions/url-rewrite-module/using-rewrite-maps-in-url-rewrite-module

<rewrites>
    <rules>
        <rule name="Redirect Rule" stopProcessing="true">
            <match url=".*" />
            <conditions>
               <add input="{StaticRedirects:{REQUEST_URI}}" pattern="(.+)" />
            </conditions>
            <action type="Redirect" url="http://www.example.com{C:1}" appendQueryString="False" redirectType="Permanent" />
        </rule>         
    </rules>
    <rewriteMaps>               
        <rewriteMap name="StaticRedirects">
            <add key="Page.aspx?id=12345" value="/newPage.aspx" />          
        </rewriteMap>       
    </rewriteMaps>
</rewrites>

I can add as many redirects as I like in the rewrite map section by adding additional keys.

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