Forum Discussion
How to modify iRule for mobile redirect to exclude a certain user agent
Hello, I have a working iRule that detects user agents using adata group named "mobile_ua_dg", then based on the site requested it redirects the request to a URL from another data group named site_redirect_dg. Everything is working fine except now we have a google search appliance that has a user agent called "secmgr" which gets redirected to mobile because in my data group we have "sec" and the logic uses contains for the data group. How can I send "secmgr" to the full site without removing "sec" from the data group or changing the logic to "equals" rather then "contains"? Below is my iRule: when HTTP_REQUEST { log local0. [IP::client_addr] log local0. [HTTP::host] log local0.info "User-Agent = [HTTP::header User-Agent]" Use full site if user has main (non-mobile) site cookie if {[HTTP::cookie site] eq "main"}{
Do not redirect clients who have manually opted for the main site
} else {
User has not manually opted for the main site
Check if the client is a mobile
if {([class match -- [string tolower [HTTP::header "User-Agent"]] contains mobile_ua_dg]) && ([class match -- [string tolower [HTTP::host]] contains site_redirect_dg])} {
set m_redirect [class match -value -- [HTTP::host] equals site_redirect_dg ]
redirect to appropriate mobile site
if {[TCP::local_port] eq "80"} {
HTTP::redirect "http://$m_redirect[HTTP::uri]"
} else {
HTTP::redirect "https://$m_redirect[HTTP::uri]"
}
}
}
}
Thanks
Bill
2 Replies
- ltwagnonRet. Employee
could you add logic to the beginning of the iRule that explicitly checks for the Google User Agent "secmgr" and if it matches, then direct the traffic to the full site? Then, if it doesn't match, use the current logic (search the data group)? Just a thought on a possible direction...
- Arie
Altostratus
Do you have access to the GSA? If so you could tweak the User-Agent. Another option is to exclude the IP-address of the GSA.
User-Agents can be tricky, especially if you search within the User-Agent string. For instance, Microsoft Edge includes the string "Chrome" in the User-Agent now...
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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