Forum Discussion

collinz1_17223's avatar
collinz1_17223
Icon for Nimbostratus rankNimbostratus
Jul 14, 2011

iRule Redirect Loop

I have setup an irule that checks the user agent string when http requests are made. If the user agent is a mobile type device (as defined in a data group) they get redirected to the mobile site.

 

 

when HTTP_REQUEST {

 

if {[class match [string tolower [HTTP::header User-Agent]] contains "mobiledevices"]} {

 

HTTP::redirect ""}

 

}

 

 

The issue is that i am get redirect loop errors. Reason being is that the user is being redirected to the same host but a different URI. This means that they are using the same VIP and the irule is being matched again.

 

 

I thought of adding in an addition if statement to check the URI (below) but i can't seem to get it to work. Any help would be greatly appreciated.

 

 

when HTTP_REQUEST {

 

if {[HTTP::uri] starts_with "/mobile"} {

 

return

 

if {[class match [string tolower [HTTP::header User-Agent]] contains "mobiledevices"]} {

 

HTTP::redirect "http://[HTTP::host]/mobile"}

 

}

 

}

 

 

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    Try this:

    
    
    when HTTP_REQUEST {
    if {([class match [string tolower [HTTP::header User-Agent]] contains "mobiledevices"]) && !([string tolower [HTTP::uri]] starts_with "/mobile")} {
      HTTP::redirect "http://[HTTP::host]/mobile"}
    }
    

    The && !() statement is the important one here. You're basically saying only redirect to /mobile if the inbound user is a mobile device that isn't already on the mobile portion of the site.

    Colin
  • Dear Colin,

     

     

    My scenario is below,

     

     

    1) When user login to http://home.example.co.in it will check for its agent, if it is normal user pass through the request, if it is mobile user redirect the request to https://mobile.example.co.in

     

     

    2) Now in web page of mobile site (https://mobile.example.co.in) user have one link IF YOU WANT TO GO MAIN SITE PLEASE CLICK HERE (http://home.example.co.in) one query string will be passed for the same i.e ismain==true and user have to redirect to http://home.example.co.in

     

     

     

    I have applied below iRule on http://home.example.co.in VS, it's working properly for redirection, it also working for query string but only in iphone and black berry for other models like windows and android it's not working.

     

     

    Could you please give me suggestion on the same.

     

     

    Regards,

     

     

    Ashish Takawale.

     

  • Hi,

     

     

    I think you should log the user agent for windows and android mobiles [log local0] and then subsequently add them in the irule condition statements

     

     

    Regards

     

    Rajesh