Using nginx, how do you serve different static files for different user agents? For example, if the current user is using an iPhone, they should be served mobile_index.html
, whereas all other user agents should be served browser_index.html
.
Found solution:
server {
listen 80;
root /var/www;
set $mobile_request '0';
if ($http_user_agent ~ 'iPhone') {
set $mobile_request '1';
}
location =/ {
if ($mobile_request = '1') {
rewrite ^ /mobile_index.html;
}
if ($mobile_request = '0') {
rewrite ^ /browser_index.html;
}
}
}