Forum Discussion

collinz1_17223's avatar
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.





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.





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




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


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







6 Replies

  • Colin_Walker_12's avatar
    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.

  • Dear Colin,



    My scenario is below,



    1) When user login to it will check for its agent, if it is normal user pass through the request, if it is mobile user redirect the request to



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




    I have applied below iRule on 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.






    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