Forum Discussion
collinz1_17223
Nimbostratus
Jul 14, 2011iRule 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"}
}
}
6 Replies
- Colin_Walker_12Historic F5 AccountTry 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 - collinz1_17223
Nimbostratus
That works perfectly, exactly what i needed.
Thanks - Colin_Walker_12Historic F5 AccountGlad to hear it. :)
Colin - Ashish_Ram_Tak1
Nimbostratus
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. - rajeshramhit_11
Nimbostratus
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 - Ashish_Ram_Tak1
Nimbostratus
how should i do that
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects
