Forum Discussion

Jim_Gray_43725's avatar
Jim_Gray_43725
Icon for Nimbostratus rankNimbostratus
Feb 08, 2012

http redirect based on path and query strings

I have a data group with 166 lines of source and target URLs for redirect. Most source URLs include 1 to 3 different queries. I need to find a way to match an incoming path and each query in any order and possibly with additional queries mixed in.

 

 

For example:

 

 

If one of the class entries is:

 

www1.domain.com/abc/xyz.do?aaa&bbb&ccc www2.domain.com/new/path.do?zzz&yyy&xxx

 

 

All of the following must match and redirect to the www2 URL:

 

 

www1.domain.com/abc/xyz.do?bbb&ccc&aaa

 

www1.domain.com/abc/xyz.do?aaa&bbb&ccc&ddd

 

www1.domain.com/abc/xyz.do?aaa&ddd&ccc&bbb

 

 

 

Does anyone have an elegant solution for this?

 

 

  • Hi Jim,

    You can parse individual query string parameters and their values using URI::query:

    http://devcentral.f5.com/wiki/iRules.uri__query.ashx

    I'm not sure what the most efficient way to handle the lookups would be though. Maybe you could always order the parameter values in the data group in the same order and then form the string to lookup in the same way.

    For example, if you have a query string like:

    param2=anothervalue&param1=avalue&param3=value3

    you would parse the values for param1, param2 and param3, concatenate them and then do a lookup against the data group which has the param values combined in the same way:

    set value [class match -value "[URI::query [HTTP::uri] param1]|[URI::query [HTTP::uri] param2]|[URI::query [HTTP::uri] param3]" equals query_string_parameters_dg]

    Your data group would have the parameter values concatenated with pipes as well:

    
    ltm data-group uri_to_pool_dg {
        records {
            anothervalue|avalue|value3 {
                data match1
            }
            anothervalue2|avalue3|value5 {
                data match2
            }
        }
        type string
    }
    

    Aaron
  • Dear Aaron,

     

     

    We are banking customer and we have decided to create mobile user login for our Internet customers, below is the senireo

     

     

    1) Initially we have www.example.in in public DNS now when this request comes to our LTM it will redirect to home.example.co.in, now when any mobile user type www.example.in in his mobile browser he will go to home.example.co.in i have assigned an iRule to the VS of home.example.co.in to redirect that traffic to lite.example.co.in and its working fine if the user is mobile user based on his OS other desktop and laptop users will straight away go to home .example.co.in.

     

     

    2) Now in another case we have given one link in a webpage of lite.example.co.in IF YOU WANT TO GO TO MAIN SITE PLEASE CLICK HERE, when user click on this link (is main==true) query string will be passed and that particular mobile user will have to move to home.example.co.in.

     

    But unfortunately we still haven't fined any solution for this, could you please help me on the 2nd case.

     

     

    Below is the iRule which we are using for mobile user redirection.

     

     

    When HTTP_REQUEST {

     

    if{ [string tolower [HTTP::header “User-Agent”]] contains “*iPhone” } {

     

    HTTP::redirect "https://lite.example.co.in"}

     

    }

     

     

     

    Could you please help me on this its an very important and high priority case, thank you in advance for your support.

     

     

    Regards,

     

     

    Ashish Takawale
  • Hi Ashish,

    Make sure to set the string you're comparing to lowercase (iPhone -> iphone). Also remove the * from the string as contains logically checks for *iphone* in the example below.

    
    when HTTP_REQUEST {
       if { [string tolower [HTTP::header "User-Agent"]] contains "iphone" } {
          HTTP::redirect "https://lite.example.co.in"
       }
    }
    

    Here are a couple of posts where we discussed options for mobile client redirects (particularly the iRule in the second example):

    https://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/86313/showtab/groupforums/Default.aspx86381

    https://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/2160890/showtab/groupforums/Default.aspx2236593

    Aaron
  • Dear Aaron,

     

     

    Below is the iRule which i am using currently, should i have to do any changes in it.

     

     

     

    when HTTP_REQUEST {

     

    switch -glob [string tolower [HTTP::header User-Agent]] {

     

    "*iphone*" -

     

    "*android*" -

     

    "*ipad*" -

     

    "*windows phone*" -

     

    "*windows ce*" -

     

    "*blackberry*" -

     

    "*symbinos*" -

     

    "*symbain os*" -

     

    "*symbian*" -

     

    "*java*" -

     

    "*winowsphone*" -

     

    "*windowsce*" {

     

    HTTP::redirect "https://lite.example.co.in/[HTTP::uri]"

     

    return

     

    }

     

    }

     

    }