Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • SiKo279 82 posts 238 karma points
    Jul 22, 2009 @ 16:13
    SiKo279
    0

    url rewrite: somepage.aspx?var=VALUE --> somefolder/value.aspx

    How do I create a urlrewrite rule that transforms:

    LocationPicker.aspx?state=WASHINGTON

    to

    service-locations/states/WASHINGTON.aspx

    I tried this:

    [code]

     

     

     

     

    <

     

    add name="statepicker"
    virtualUrl="~/LocationPicker.aspx?state=(.*)"
    rewriteUrlParameter="ExcludeFromClientQueryString"
    destinationUrl="~/service-locations/states/$1.aspx"
    ignoreCase="true" />

    [/code]

    but it doesn't seem to be picked up (do I need to reset the app pool?)

    Any suggestions welcome.

     

     

  • Powellze 38 posts 73 karma points
    Jul 22, 2009 @ 17:22
    Powellze
    0

    The Url Rewriting uses regular expressions so I think you need the ^ at the start of the Virtual URL ( ^ = carat?) which tells the regular expression to start the match from the start of the string

    Here is an example from the UrlReqriting.config

    <urlrewritingnet xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
    <rewrites>
    <add name="produktidrewrite"
    virtualUrl="^~/product/(.*).aspx"
    rewriteUrlParameter="ExcludeFromClientQueryString"
     destinationUrl="~/product.aspx?productid=$1"
    ignoreCase="true" /> 
    </rewrites>
    </urlrewritingnet>

    I will have a look to see if i have a good example and get back to you.

     

  • SiKo279 82 posts 238 karma points
    Jul 23, 2009 @ 11:26
    SiKo279
    0

    Well, so far I haven't had any luck with this.

    Is anyone using this with umbraco?

    I'm gonna go for another solution: change the LocationPicker.aspx reference in my html code :-s

  • Powellze 38 posts 73 karma points
    Jul 23, 2009 @ 12:34
    Powellze
    0

    After doing some playing about with umbraco and the UrlRewriting, it doesn't look possible from a QueryString.

     

    This must be to do with the path only being processed (not 100% sure on this but looks very likely).

     

    So to summarise for you, it is possible to do it the other way round ie page to another page with a query string appended:

    Courtesy of CWS: The sample below rewrites a url from "/product/someproductid.aspx" to  "/product.aspx?productid=someproductid"

    <add name="CWS_emaiAFriendID" virtualUrl="^~/email-a-friend/(.[0-9]*).aspx" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/email-a-friend.aspx?nodeID=$1" ignoreCase="true" />
  • Powellze 38 posts 73 karma points
    Jul 23, 2009 @ 12:41
  • Powellze 38 posts 73 karma points
    Jul 23, 2009 @ 13:20
    Powellze
    100

    Got it, we needed to escape the question mark

    Try this:

    This example keeps the URL as is

    <add name="MyExample" virtualUrl="^~/\?mytest=(.*)" rewriteUrlParameter="IncludeQueryStringForRewrite" destinationUrl="~/mypage/$1" ignoreCase="true" />

    This example changes the URL to the new one

    <add name="MyExample" redirect="Application"  virtualUrl="^~/\?mytest=(.*)" rewriteUrlParameter="IncludeQueryStringForRewrite" destinationUrl="~/mypage/$1" ignoreCase="true" />
  • SiKo279 82 posts 238 karma points
    Jul 23, 2009 @ 14:25
    SiKo279
    0

    Fabulous!!!

    That works exactly!

    Great stuff, thanks for sorting this out... RegEx is great, but nitty gritty ;-)

    Thank you!

  • SiKo279 82 posts 238 karma points
    Jul 23, 2009 @ 14:34
    SiKo279
    0

    Well, I was a bit too soon calling it all good ... :-(

    I guess in my enthousiasm I clicked on the destination node from within the umbraco admin app ...

    It still doesn't work

    Page not found

    No umbraco document matches the url 'http://local.cms.development:90/LocationPicker.aspx?state=WASHINGTON'

    [code]

    <add name="statepicker"
             redirect="Application"
             virtualUrl="^~/\?state=(.*)"
             rewriteUrlParameter="IncludeQueryStringForRewrite"
             destinationUrl="~/service-locations/states/$1"
             ignoreCase="true" />

    [/code]

    I try to tinker with it a bit myself ... RegEx doesn't seem to want to enter my brain atm :( 

  • SiKo279 82 posts 238 karma points
    Jul 23, 2009 @ 14:38
    SiKo279
    0

    [code]    <add name="statepicker"
             redirect="Application"
             virtualUrl="^~/LocationPicker.aspx\?state=(.*)"
             rewriteUrlParameter="IncludeQueryStringForRewrite"
             destinationUrl="~/service-locations/states/$1.aspx"
             ignoreCase="true" />[/code]

    WORKS!!!

     

    Thanks for getting me on track!!

  • Powellze 38 posts 73 karma points
    Jul 23, 2009 @ 16:14
    Powellze
    1

    No worries, I am glad that worked :)

    Shout up if you have any further problems.

Please Sign in or register to post replies

Write your reply to:

Draft