Question

I need to redirect users to specific page if their user-agent is not WebKit family. Is it possible to do by using nginx?

Was it helpful?

Solution

Yes, you can use the $http_user_agent variable to check against it

set $webkit_rewrite do_not_perform;

## http_user_agent for webkit ##
if ($http_user_agent ~* WebKit) {
  set $webkit_rewrite perform;
}

## redirect to webkit.example.com ##
if ($webkit_rewrite = perform) {
  rewrite ^ http://m.example.com$request_uri? redirect;
  break;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top