How to redirect outdated browsers with NGinx map?
We have an NginX balancing proxy in front of our web application. Unfortunately there is not enough development resources to support outdated browsers, yet :( We want to redirect members of our web project to /outdated page by their browser user-agent data like this (https://www.in2circle.com/outdated). For some reason we don't want to load back-end with User-Agent content analysis logic. I've heard it's easy to do with NginX http://nginx.org/en/docs/http/ngx_http_map_module.html If somebody did so, can you help me with examples and explanations, please!
Next solution works pretty good and is exactly what I wanted:
map $http_user_agent $outdated {
default 0;
"~MSIE [1-9]\." 1;
"~Mozilla.*Firefox/[1-9]\." 1;
"~Mozilla.*Firefox/[0-2][0-9]\." 1;
"~Mozilla.*Firefox/3[0-1]\." 1;
"~Opera.*Version/[0-9]\." 1;
"~Opera.*Version/[0-1][0-9]\." 1;
"~Opera.*Version/2[0-1]\." 1;
"~AppleWebKit.*Version/[0-6]\..*Safari" 1;
"~Chrome/[0-9]\." 1;
"~Chrome/[0-2][0-9]\." 1;
"~Chrome/3[0-3]\." 1;
}
if ($outdated = 1){
rewrite ^ /outdated redirect;
}
Thanks everyone for Help/Answers.
A simply test is sufficient:
location / {
if ($http_user_agent ~ "MSIE 6.0" ) {
set $browser-version outdated;
}
if ($http_user_agent ~ "MSIE 7.0" ) {
set $browser-version outdated;
}
if ($http_user_agent ~* "(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino") {
set $browser-version mobile;
}
if ( $uri ~ ^/(images|favicon\.ico) ) {
set $browser-version independent;
}
if ($browser-version = outdated) {
rewrite ^ /outdated/index.html break;
}
if ($browser-version = mobile) {
rewrite ^ /mobile/index.html break;
}
}