LimitBrowsers

The following explains how to limit browser support to only recent versions of Chrome, Firefox, Internet Explorer and Safari (+ Mobile Safari and Palm Pre).


 * 1) Supported browsers
 * 1) Supported browsers

modern_browser gecko 1.9;

modern_browser safari 3.0; modern_browser safari 3.1; modern_browser safari 3.2; modern_browser safari 4.0;
 * 1) note that Safari related directives match
 * 2) Chrome, Mobile Safari, Palm Pre and other WebKit-based browsers here, too, thanks
 * 3) to all of them using almost identical User-Agent strings

modern_browser msie 7.0; modern_browser msie 8.0;

modern_browser unlisted;


 * 1) Non-supported browsers
 * 1) Non-supported browsers

ancient_browser msie 4.0; ancient_browser msie 5.0; ancient_browser msie 5.5; ancient_browser msie 6.0;

ancient_browser opera 7; ancient_browser opera 8; ancient_browser opera 9; ancient_browser opera 10;
 * 1) Here is how one can disable support of a specific browser

ancient_browser konqueror 3; ancient_browser konqueror 4;

ancient_browser Links Lynx Netscape4;


 * 1) Now, to the fun part. If we perform a rewrite on every
 * 2) request here, images won't be displayed, so we have to
 * 3) do some extra work besides just
 * 4) if ($ancient_browser){
 * 5) rewrite ^ /unsupported_browser.html;
 * 6) break;
 * }
 * 1) break;
 * }

set $unsupported_browser_rewrite do_not_perform;

if ($ancient_browser){ set $unsupported_browser_rewrite perform; }

if ($uri !~* /\.(jpeg|jpg|png|ico|gif|js|css)$/) { set $unsupported_browser_rewrite do_not_perform; }

if ($unsupported_browser_rewrite = perform){ rewrite ^ /unsupported_browser.html; break; }