wiki:nginx_redirect_rewrites
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| wiki:nginx_redirect_rewrites [2022/09/23 12:42] – created antisa | wiki:nginx_redirect_rewrites [2023/01/11 13:43] (current) – add Rewrite uppercase to lowercase antisa | ||
|---|---|---|---|
| Line 46: | Line 46: | ||
| You can check the rewrite messages in specified error log. | You can check the rewrite messages in specified error log. | ||
| + | |||
| + | ===== Redirect based on browser' | ||
| + | server conf: | ||
| + | <code nginx> | ||
| + | | ||
| + | return 301 / | ||
| + | } | ||
| + | |||
| + | location /it { | ||
| + | proxy_pass http://ups; | ||
| + | proxy_set_header Host $host; | ||
| + | } | ||
| + | |||
| + | location /en { | ||
| + | proxy_pass http:// | ||
| + | proxy_set_header Host $host; | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | In http context add the mapping for '' | ||
| + | <code nginx> | ||
| + | |||
| + | http { | ||
| + | ... | ||
| + | | ||
| + | map $http_accept_language $lang { | ||
| + | default en; | ||
| + | ~it it; | ||
| + | ~es es; | ||
| + | ~fr fr; | ||
| + | } | ||
| + | | ||
| + | ... | ||
| + | |||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== Rewrite uppercase to lowercase ===== | ||
| + | Install perl module first: | ||
| + | |||
| + | apt install nginx-module-perl | ||
| + | |||
| + | Enable it in // | ||
| + | load_module " | ||
| + | |||
| + | Create perl rewrite function inside //http// section: | ||
| + | <code nginx> | ||
| + | # Include the perl module | ||
| + | perl_modules perl/lib; | ||
| + | |||
| + | # rewrite function from upper to lowercase | ||
| + | perl_set $uri_lowercase 'sub { | ||
| + | my $r = shift; | ||
| + | my $uri = $r->uri; | ||
| + | $uri = lc($uri); | ||
| + | return $uri; | ||
| + | }'; | ||
| + | </ | ||
| + | |||
| + | Use it in site configuration, | ||
| + | <code nginx> | ||
| + | # if the path contains uppercase characters, | ||
| + | # rewrite to lowercase | ||
| + | location ~ [A-Z] { | ||
| + | | ||
| + | } | ||
| + | </ | ||
| + | |||
| ====== Tested on ====== | ====== Tested on ====== | ||
| * Debian 11 | * Debian 11 | ||
wiki/nginx_redirect_rewrites.1663936965.txt.gz · Last modified: by antisa
