Forum Discussion
Detecting Mobile Devices and Redirecting to different URL
Dear Dev Team,
-> Curretly we have the below iRule.
==========================================================
when HTTP_REQUEST {
switch [string tolower [HTTP::host]] {
"www.test.com" -
"test.com" -
"10.1.1.1" {
Check and redirect request
switch [string tolower [HTTP::path]] {
"/" -
"/abc/123" {HTTP::redirect "http://www.test.com/abc/123/mypage/?reset=true"}
}
}
}
}
==========================================================
New requirement is, apart from the above, if any mobile device(need to be detected by iRule) who is trying to access the same "www.test.com" or "www.test.com/abc/123" URL need to be redirected to "http://www.test.com/abc/123/mypage/mobile-page"
Could you pls help me on this?
Thank you in advance!
10 Replies
- What_Lies_Bene1
Cirrostratus
Create a Data Group with the relevant mobile User Agent strings call 'user-agent-dg' and then update your iRule as follows;when HTTP_REQUEST { switch [string tolower [HTTP::host]] { "www.test.com" - "test.com" - "10.1.1.1" { Check and redirect request switch [string tolower [HTTP::path]] { "/" - "/abc/123" { if { [class match [string tolower [HTTP::header User-Agent]] contains user-agent-dg ] } { HTTP::redirect "http://www.test.com/abc/123/mypage/mobile-page" } else { HTTP::redirect "http://www.test.com/abc/123/mypage/?reset=true" } } } } } } - muzammil_88686
Nimbostratus
Dear Steve,
Thank you for your quick response!
Could you help me how can I create a DG for different mobile devices? Is there any other post or article I can refer? - What_Lies_Bene1
Cirrostratus
In the GUI go to: Local Traffic > iRules > Data Group List > Create > Type: String and enter each user agent string you want to check for in the string field, leave the value field blank. - muzammil_88686
Nimbostratus
Thank you Steve!
How can I log if the Mobile device is detected? I tried using the log as below in If statement but it is not working.
if { [class match [string tolower [HTTP::header User-Agent]] contains user-agent-dg ] } {
HTTP::redirect "http://www.test.com/abc/123/mypage/mobile-page"
log local0. "[IP::client_addr]:[TCP::client_port]: UA: [HTTP::header "User-Agent"], redirecting"
}
else {
HTTP::redirect "http://www.test.com/abc/123/mypage/?reset=true" }
} - What_Lies_Bene1
Cirrostratus
Can you clarify not working please? Also, remove the quotation marks "" from "User-Agent". - muzammil_88686
Nimbostratus
Dear Steve,
Thank you! Now I m able to see the logs. - What_Lies_Bene1
Cirrostratus
You're welcome, glad it's working.
- muzammil_88686
Nimbostratus
Dear Steve,
I have one more question...
I have created a Datagroup using GUI with the below strings.
android
blackberry
palm
sonyericsson
nokia
samsung
symbian
Want to know the below things.
1) I have defined the above strings using small letters. Is this strings are case sensitive? I mean, since I have defined "android", if any request is coming with "Android" then still it will work?
2) Also I have noted that when I add strings "sie" and "windows" PC users(not mobile users) then the URL is redirecting to Mobile page instead of normal page
3) Could you help me getting the most popular Mobile devices strings which I can add in Datagroup? - hoolio
Cirrostratus
Hi muzammil,
Here's a related post with some suggestions:
https://devcentral.f5.com/community/group/aft/86313/asg/5086381
Aaron - MikeJConnect_35
Nimbostratus
It is very old post but I have got similar requirement.
Is there a possibility to detect if a mobile app installed in iPhone or Android, and if the particular app installed redirect it to a link1 otherwise redirect to a different link2. Pseudocode is something like this;
check if the mobile device has facebook(for example) True: 1 redirect to false: 2 redirect to
Is this possible to implement in F5 using iRules or some otherway?
TIA, John
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