Skip to content

Instantly share code, notes, and snippets.

@atomsfat
Created August 30, 2016 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atomsfat/82c488b2118d7639b15d28145f58ca31 to your computer and use it in GitHub Desktop.
Save atomsfat/82c488b2118d7639b15d28145f58ca31 to your computer and use it in GitHub Desktop.
Mobile Device Detection via User Agent RegEx Varnish
#Mobile detect https://gist.github.com/dalethedeveloper/1503252
if(req.http.User-Agent ~ ".*(Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune).*")
{
set req.http.X-ua = "mobile";
}else{
set req.http.X-ua = "desktop";
}
sub vcl_hash {
hash_data(req.http.X-ua + ":" + req.url );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment