Forum Discussion
Damien_Turner_1
Nimbostratus
Aug 02, 2010Redirect if your a mobile user....
Hi all, I was wondering if I could have some help!
I have been asked if it is possible to use an iRule to redirect a mobile user to a new URL.
An example would be....
user on an iPhone goes to www.mysite.com but as they are a mobile user the URL gets changed to m.mysite.com and the correct formatted site is then shown.
I've looked through quite a few similar topics but none seem to redirect the URL.
I have a a pool of web servers but they serve all traffic, but I guess I could create anther pool.
I'm still quite new to iRules but I know they rule!
Thank You
Damien
11 Replies
- Chris_Miller
Altostratus
Damien,when HTTP_REQUEST { if { [HTTP::header "User-Agent"] contains "iPhone"] } { HTTP::redirect "http://m.mysite.com" } }
- Damien_Turner_1
Nimbostratus
Hi Chris thank you for replying.when HTTP_REQUEST { if { [HTTP::header "User-Agent" ] equals $::MobileUserAgents } { HTTP::redirect "http://mobile.holidayextras.co.uk" } Uncomment the line below to turn on logging. log local0. " Mobile Redirected" } The datagroup then has string *iPhone* *iPad* etc My iRule editor said it has passed the checker which is always a good sign! Regards Damien
- hoolio
Cirrostratus
If you change equals to contains that should work. If you're on 9.4.4 or higher, you should remove the $:: prefix from the reference to the datagroup name in the iRule. You might also want to preserve the originally requested URI in the redirect using 'HTTP::redirect "http://mobile.example.co.uk[HTTP::uri]". - Damien_Turner_1
Nimbostratus
Hi Aaron thank you for helping me again, I have made the changes so my rule now looks like this....when HTTP_REQUEST { if { [HTTP::header "User-Agent" ] contains $::MobileUserAgents } { HTTP::redirect "http://mobile.holidayextras.co.uk[HTTP::uri]" log local0. "iPhone Found" } Uncomment the line below to turn on logging. log local0. "Mobile Redirected: [HTTP::header "User-Agent"] -Phone Redirected" }code] My DataGroup is a string with.... *iPhone* *iPad* *iPod* I like My Apple stuff! But the iRule dosn't seem to be working as nothing is being written to the log, if I turn on the global log I can see iPhone user agents passing through.... Aug 4 09:33:17 tmm tmm[1800]: Rule Mobile_UserAgent_Redirect_iRule : Mobile Redirected: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) -Phone Redirected Aug 4 09:33:17 tmm tmm[1800]: Rule Mobile_UserAgent_Redirect_iRule : Mobile Redirected: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) -Phone Redirected Aug 4 09:33:17 tmm tmm[1800]: Rule Mobile_UserAgent_Redirect_iRule : Mobile Redirected: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) -Phone Redirected Aug 4 09:33:17 tmm tmm[1800]: Rule Mobile_UserAgent_Redirect_iRule : Mobile Redirected: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) -Phone Redirected Aug 4 09:33:17 tmm tmm[1800]: Rule Mobile_UserAgent_Redirect_iRule : Mobile Redirected: Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A306 Safari/6531.22.7 -Phone Redirected Aug 4 09:33:17 tmm tmm[1800]: Rule Mobile_UserAgent_Redirect_iRule : Mobile Redirected: Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A306 Safari/6531.22.7 -Phone Redirected Aug 4 09:33:17 tmm tmm[1800]: Rule Mobile_UserAgent_Redirect_iRule : Mobile Redirected: Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A306 Safari/6531.22.7 -Phone Redirected Aug 4 09:33:18 tmm tmm[1800]: Rule Mobile_UserAgent_Redirect_iRule : Mobile Redirected: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) -Phone Redirected I'm confused! Also you said if I'm running 9.4.4 then I should remove the $:: from the datagroup, I have 9.4.8 HF4 running but it wont let me take out the $::, when I try and pass the rule through the irule editor it keeps telling me my irule is invalid. Thank you for your help guys!
- hoolio
Cirrostratus
Hi Damien, - Damien_Turner_1
Nimbostratus
Hi Aaron, I missed that one too!when HTTP_REQUEST { if {[matchclass [HTTP::header "User-Agent" ] contains $::MobileUserAgents] } { HTTP::redirect "http://m.holidayextras.co.uk[HTTP::uri]" log local0. "iPhone Found" } Uncomment the line below to turn on logging. log local0. "Mobile Redirected: [HTTP::header "User-Agent"] -Phone Redirected" } But its not picking up my iphone, could I have the information in the dataclass wrong?
- hoolio
Cirrostratus
Can you remove the * from the datagroup entries? Those will be interpreted literally--not as wildcards.when HTTP_REQUEST { log local0. "[IP::client_addr]:[TCP::client_port]: UA: [HTTP::header "User-Agent"]" if {[matchclass [HTTP::header "User-Agent"] contains $::MobileUserAgents] } { HTTP::redirect "http://m.holidayextras.co.uk[HTTP::uri]" log local0. "[IP::client_addr]:[TCP::client_port]: UA: [HTTP::header "User-Agent"], redirecting" } }
- Damien_Turner_1
Nimbostratus
Hi Aaron, taking the * out of the datagroup fixed it, the iRule now see's my iPhone and redirects. - pmaubo2_55685
Nimbostratus
Hi, - Nicolas_Pla_681
Nimbostratus
Hi, i have a list of almost all mobile devices in this irule. hope that you find it usefull
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