Skip to content

Instantly share code, notes, and snippets.

@ragingwind
Created August 5, 2019 09:19
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ragingwind/f19a2751adccc503074184f611e6864a to your computer and use it in GitHub Desktop.
Save ragingwind/f19a2751adccc503074184f611e6864a to your computer and use it in GitHub Desktop.
Redirect old-classic browser including IE 11
worker_processes 1;
events {
worker_connections 1024;
}
http {
map $http_user_agent $outdated {
default 0;
"~MSIE [1-10]\." 1;
"~Trident/[5-7]\." 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;
}
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
if ($outdated = 1) {
rewrite ^ /outdated.html redirect;
}
}
location = /outdated.html {
root /usr/share/nginx/html;
index outdated.html;
}
}
}
@Frisch12
Copy link

The line

"~MSIE [1-10]\."                        1;

Should be

"~MSIE [0-9]+\."                        1;

@ragingwind
Copy link
Author

I think 1-10 is right. the last number of msie is 10 https://www.whatismybrowser.com/guides/the-latest-user-agent/internet-explorer

@cgfeel
Copy link

cgfeel commented May 22, 2023

Very helpful for me

@Frisch12
Copy link

I think 1-10 is right. the last number of msie is 10 https://www.whatismybrowser.com/guides/the-latest-user-agent/internet-explorer

Yeah maybe, however a regex group is not like a number until another number it is a bunch of ascii characters. So with 1-10 you say you allow the digits 1, 1 and 0 just once, not 1-10 like decimal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment