Redirecting old IE users to different URL with nginx

internet-explorer, nginx

Solution

You have to use regexp to match all cases. eg.

location / {
    if ($http_user_agent ~* '(MSIE 8.0|MSIE 7.0)') {
        return 301 https://$host$request_uri; 
    }
}

Problem

I'm able to serve old IE users a outdated browser page by using the following snippet in my server block: ``` location / { if ($http_user_agent ~ "MSIE 8.0") { rewrite ^ /ie.html break; } } ``` This works fine, and nginx serves `ie.html` to IE 8 users. I have two questions, though. One is that I would like to redirect old IE users to `/upgradebrowser` rather than just serving them a HTML page. Is there a way I can send a `Location:` header or something? Second, is there any way for me to easily catch all older users of IE? At the moment this is just doing IE 8.0, is there a way to use `$http_user_agent < "MSIE 8.0"`?

Original source