Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NGINX configuration to detect and redirect unsupported browsers
# # IE 10 +
# # Firefox 27 +
# # Safari 7 +
# # iOS Safari 5 +
# # IE mobile 10 +
# # Android 4.2 +
# # Blackberry 10 +
# # Chrome 31+
#
# Supported browsers
#
# modern_browser_value "modern.";
# Firefox 27s
modern_browser gecko 27.0.0;
modern_browser msie 10.0;
modern_browser msie 11.0;
modern_browser safari 7.0;
# modern_browser opera 9.0;
# modern_browser konqueror 3.0;
modern_browser unlisted;
#
# Non-supported browsers
#
ancient_browser "MSIE 6.0";
ancient_browser msie 1.0;
ancient_browser msie 1.5;
ancient_browser msie 2.0;
ancient_browser msie 3.0;
ancient_browser msie 4.0;
ancient_browser msie 5.0;
ancient_browser msie 5.5;
ancient_browser msie 6.0;
ancient_browser msie 7.0;
ancient_browser msie 8.0;
ancient_browser msie 9.0;
ancient_browser safari 3;
ancient_browser safari 4;
ancient_browser safari 5;
ancient_browser gecko 1;
ancient_browser gecko 2;
ancient_browser gecko 3;
ancient_browser gecko 4;
ancient_browser gecko 5;
ancient_browser gecko 6;
ancient_browser gecko 7;
ancient_browser gecko 8;
ancient_browser gecko 9;
ancient_browser gecko 10;
ancient_browser gecko 11;
ancient_browser gecko 12;
ancient_browser gecko 13;
ancient_browser gecko 14;
ancient_browser gecko 15;
ancient_browser gecko 16;
ancient_browser gecko 17;
ancient_browser gecko 18;
ancient_browser gecko 19;
ancient_browser gecko 20;
ancient_browser gecko 21;
ancient_browser gecko 22;
ancient_browser gecko 23;
ancient_browser gecko 24;
ancient_browser gecko 25;
ancient_browser gecko 26;
ancient_browser opera 7;
ancient_browser opera 8;
ancient_browser opera 9;
ancient_browser opera 10;
ancient_browser konqueror 3;
ancient_browser konqueror 4;
ancient_browser Links Lynx Netscape4;
if ($http_user_agent ~ "MSIE 6.0" ) {
set $ancient_browser 1;
}
if ($ancient_browser) {
rewrite ^ https://www.mysite.com/unsopported.html;
}
@vadjs

This comment has been minimized.

Copy link

@vadjs vadjs commented Jul 18, 2018

if you need to detect modern IE in compatibility mode You can add this code in line 88:

if ($http_user_agent ~ 'Trident/7.0' ) {
    set $ancient_browser 0;
}

Full list of IE headers in compatibility mode below:

IE7: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1;...)
IE8: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0;...)
IE8 Compatibility View: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0;...)
IE9: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
IE9 Compatibility View: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/5.0;...)
IE10 Compatibility View Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; WOW64; Trident/6.0;...
IE11 Compatibility View : Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment