« Previous Next »

Answered Thread: What am I doing wrong?

Last post 11-13-2008 11:46 AM by ruslany. 4 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (5 items)

Sort Posts:

  • 11-12-2008, 7:10 AM

    • Stoobs
    • Not Ranked
    • Joined on 11-12-2008, 11:59 AM
    • Posts 6

    What am I doing wrong?

    Okay, I want requests to http://localhost/article.aspx?AccommodationCode={code} need to go to http://localhost/article.aspx?ISDLNK=1&ACODE={code}&TINDEXPD=0

    {code} can be many things, such as E1234 for example..

     I put this rule in, but it doesn't redirect?

    <rule name="Redirect Testing" stopProcessing="true">

    <match url=".*/article.aspx.*" />

    <action type="Redirect" url="article.aspx?ISDLNK=1&amp;ACODE={C:1}&amp;TINDEXPD=0" appendQueryString="true" />

    <conditions>

    <add input="{QUERY_STRING}" pattern="AccommodationCode=([_0-9a-z-]+)" /> </conditions>

    </rule>

     Any clues to why it isn't redirecting?

     

    The example at http://learn.iis.net/page.aspx/461/creating-rewrite-rules-for-the-url-rewrite-module/ works correctly, so I don't think it has anything to do with the rewrite module not running correctly..

  • 11-12-2008, 12:38 PM In reply to

    • Stoobs
    • Not Ranked
    • Joined on 11-12-2008, 11:59 AM
    • Posts 6

    Re: What am I doing wrong?

     Never mind, fixed it..

     

    But now I've found another issue..

    I'm prepping a site migration at the moment from one old webapp, to a brand new one, unfortunately virtually all of the querystrings are different, and a lot of the values no longer apply..

    Ideally I want to run various lookups on the querystring and redirect to the new page(s), one good method I though would be to use the funky new rewrite maps, but it appears that it only works with static URLs?

    If I use the following rule:

                    <rule name="Redirect to new pages" stopProcessing="true">
                        <match url="articles.aspx\?(ArticleID=[0-9]+).*" />
                        <conditions>
                            <add input="{ArticleRedirects:{R:1}}" pattern="(.+)" />
                        </conditions>
                        <action type="Redirect" url="newarticles.aspx?RCODE={C:1}" appendQueryString="true" />
                    </rule>

     <rewriteMap name="ArticleRedirects">
                    <add key="ArticleID=2" value="898" />

    </rewriteMap>

    ..to look up the ArticleID equivilent on the new site, then use that value in the redirect action.. but it doesn't work..

     

    The other way is to use a more standard lookup and pass in the querystring to perform the lookup, but it will only look up the exact querystring, so if there are any other querystrings added on for tracking etc, the redirect will fail..

      <rule name="Redirect to New Pages 2" stopProcessing="true">
                        <match url="articles.aspx.*" />
                        <conditions>
                            <add input="{ArticleRedirects:{QUERY_STRING}}" pattern="(.+)" />
                        </conditions>
                        <action type="Redirect" url="newArticles.aspx?RCODE={C:1}" appendQueryString="true" />
                    </rule>

     There must be an easy way around this, other than having a map entry for every single eventuality, or an equally large number of standard redirect rules?

  • 11-12-2008, 12:53 PM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 3:38 PM
    • Redmond, WA
    • Posts 670

    Answered Re: What am I doing wrong?

    I think you could modify the rule to make it work:

    <rule name="Redirect to New Pages 2" stopProcessing="true">
                        <match url="articles.aspx$" />
                        <conditions>
                            <add input="{QUERY_STRING}" pattern="(?:^|&)articleID=([0-9]+)(?:$|&)" />
                            <add input="{ArticleRedirects:{C:1}}" pattern="(.+)" />
                        </conditions>
                        <action type="Redirect" url="newArticles.aspx?RCODE={C:1}" appendQueryString="true" />
                    </rule>

    <rewriteMap name="ArticleRedirects">
                    <add key="2" value="898" />
    </rewriteMap>

    This way the rewrite map will contain only the mappings from old ID's to new ID's. Plus the rule should work even if query string contains some other parameters.

    Note that the pattern in the <match> element of the rule is matched agains the URL path that does not contain query string, so the pattern in the first rule example "Redirect to new pages" would never match.

    http://ruslany.net
  • 11-13-2008, 4:47 AM In reply to

    • Stoobs
    • Not Ranked
    • Joined on 11-12-2008, 11:59 AM
    • Posts 6

    Re: What am I doing wrong?

     That's absolutely perfect!

     It was a bit fustrating as there is very little documentation out there at the moment (you're not planning on writing an idiots guide to the rewrite module anytime soon are you? ;)), but that has been a huge help :)

     Using that as the basis, I should be able to do everything I need to now :)

     

    Cheers!

  • 11-13-2008, 11:46 AM In reply to

    • ruslany
    • Top 25 Contributor
    • Joined on 07-01-2007, 3:38 PM
    • Redmond, WA
    • Posts 670

    Re: What am I doing wrong?

    There are many articles about using URL rewrite module available here http://learn.iis.net/page.aspx/460/using-url-rewrite-module.

    http://ruslany.net
Page 1 of 1 (5 items)
Microsoft Communities