Forum Discussion

Jim_Gray_43725's avatar
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:



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




Does anyone have an elegant solution for this?



5 Replies

  • Hi Jim,

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

    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:


    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

  • 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 in public DNS now when this request comes to our LTM it will redirect to, now when any mobile user type in his mobile browser he will go to i have assigned an iRule to the VS of to redirect that traffic to 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



    2) Now in another case we have given one link in a webpage of 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


    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.





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


    HTTP::redirect ""}






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






    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 ""

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

  • 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 "[HTTP::uri]"