Forum Discussion

Brian_Kenworthy's avatar
Brian_Kenworthy
Icon for Nimbostratus rankNimbostratus
Aug 30, 2012

Redirect to New Page but Pass Query String Parameters

Hi All,

 

 

Need some advice on what an iRule would look like to do this....We are moving from legacy ASP listeners to .net listeners, but we don't want the client to change their endpoint until they are ready. So here's what it we are looking to do:

 

 

redirect requests destined for:

 

https://my.domain.com/vendor/status.asp?user=xxx&password=yyy

 

to

 

https://my.domain.com/vendor/status.aspx?user=xxx&password=yyy

 

 

I know how to redirect the whole URI, but am confused about how to change just one piece:

 

 

when HTTP_REQUEST {

 

HTTP::redirect "https://[HTTP::host][HTTP::uri]"

 

}

 

 

Thanks for your help in advance!!

 

BK
  • Hi Brian,

    You are already most of the way there with what you need, but you were performing the same process for both of them.

    The "-" on the end tells the qualifying event to perform the same action as the next event, so you need to seperate the actions for each specific HTTP::uri.

    In a switch statement the values in the "" are literal, so these are detecting the first part of the URI Path do differentiate them. The -glob allows for the use of the "*" Wildcard which will match anything else after what you are looking for.

    "/vendorABC/status.asp*"

    "/vendorXYZ/status.asp*"

    Also, in your switch statement you are performing a string to lower for the comparison, so when you are performing a string tolower make sure that the values are all in lower case so that you get a match.

    "/vendorABC/status.asp*"

    "/vendorXYZ/status.asp*"

    Should be:

    "/vendorabc/status.asp*"

    "/vendorxyz/status.asp*"

    Try this:

    
    when HTTP_REQUEST {
    switch -glob [string tolower [HTTP::uri]] {
    "/client/order.asp*" -
    "/vendorabc/status.asp*" {
    log local0. "Rewriting [HTTP::uri] to [string map -nocase {{VendorABC} {Listeners} {status.asp?} {abcstatus.ashx?}} [HTTP::uri]]" 
    HTTP::uri [string map -nocase {{VendorABC} {Listeners} {status.asp?} {abcstatus.ashx?}} [HTTP::uri]]
    pool beta.res-direct.com_B2B_HTTP
    }
    "/vendorxyz/status.asp*" {
    log local0. "Rewriting [HTTP::uri] to [string map -nocase {{VendorXYZ} {Listeners} {status.asp?} {xyzstatus.ashx?}} [HTTP::uri]]" 
    HTTP::uri [string map -nocase {{VendorXYZ} {Listeners} {status.asp?} {xyzstatus.ashx?}} [HTTP::uri]]
    pool beta.res-direct.com_B2B_HTTP
    }
    }
    } 
    

    Hope this helps.
  • Perfect, this is working exactly as we expect. Thanks so much for the explanation of the rule elements Michael, that helps to understand exactly what's happening.

     

     

    Thanks to Kevin and Aaron as well for your help, you guys all rock!