Base Domain Redirect with user-agent detection
I have the rule below in place and it works, but I have to create a seperate irule for every domain I host. I'm trying to create a single rule that I can use on all of my digital properties. The requirement is all requests from mobile devices will redirect to the m. version of the site. I can do this with string replace, but that doesn't work for a "base domain" request.
hostnames to replace:
domain.com
www.domain.com
shop.domain.com
Here is the 2 rules I have:
The problem with this rule is that i have to specify the "domain.com" in the redirect, so I have to create a separate irule for every domain.
when HTTP_REQUEST {
if {[HTTP::cookie exists "MobileOptOut"]}{
return
}
switch -glob [string tolower [HTTP::header User-Agent]] {
"*iphone*" -
"*mobile*" -
"*ipod*" -
"*blackberry*" -
"*opera\ mobi*" -
"*htc*" -
"*silk*" -
"*googlebotmobile*" -
"*msn\ mobile\ proxy*" -
"*android*" {
HTTP::redirect http://m.domain.com[HTTP::uri]
return
}
}
}
The problem with this rule is that it will not redirect the base domain "domain.com"
when HTTP_REQUEST {
if {[HTTP::cookie exists "MobileOptOut"]}{
return
}
switch -glob [string tolower [HTTP::header User-Agent]] {
"*iphone*" -
"*mobile*" -
"*ipod*" -
"*blackberry*" -
"*opera\ mobi*" -
"*htc*" -
"*silk*" -
"*googlebotmobile*" -
"*msn\ mobile\ proxy*" -
"*android*" {
HTTP::redirect "http://[string map -nocase {"www." "m." } [HTTP::host]][HTTP::uri]"
return
}
}
}
Does anyone have any ideas how I can strip out the base domain from the request and redirect to m.domain.com?
TIA - Clayton