Appendix C: Scripts : Examples : Redirect mobile users to the mobile version of a website
 
Redirect mobile users to the mobile version of a website
The content rewriting feature does not support matching the User-Agent header. You can write a script that detects User-Agent headers that identify mobile device users and redirect them to the mobile version of a website.
-- Redirect mobile users to the mobile version of a website by parsing the User-Agent header
when RULE_INIT {
debug("detect User-Agent and go to mobile site\n")
}
 
when HTTP_REQUEST{
path = HTTP:path_get()
debug("path=%s\n",path)
agent = HTTP:header_get_value("User-Agent")
if agent:lower():find("iphone") or agent:lower():find("ipad") then
debug("found iphone or ipad in User-Agent %s \n", agent)
HTTP:redirect("https://m.mymobilesite.com/%s",path)
end
}