How i can translate uppercase to lowercase letters in a rewrite rule in nginx web server? How i can translate uppercase to lowercase letters in a rewrite rule in nginx web server? nginx nginx

How i can translate uppercase to lowercase letters in a rewrite rule in nginx web server?


Yes, you are going to need perl. If you are using Ubuntu, instead of apt-get install nginx-full, use apt-get install nginx-extras, which will have the embedded perl module.Then, in your configuration file:

  http {  ...    # Include the perl module    perl_modules perl/lib;    ...    # Define this function    perl_set $uri_lowercase 'sub {      my $r = shift;      my $uri = $r->uri;      $uri = lc($uri);      return $uri;    }';    ...    server {    ...      # As your first location entry, tell nginx to rewrite your uri,      # if the path contains uppercase characters      location ~ [A-Z] {        rewrite ^(.*)$ $scheme://$host$uri_lowercase;      }    ...


i managed to achieve the goal using embedded perl:

location ~ [A-Z] {  perl 'sub { my $r = shift; $r->internal_redirect(lc($r->uri)); }';}


location /dupa/ {    set_by_lua $request_uri_low "return ngx.arg[1]:lower()" $request_uri;    rewrite ^ https://$host$request_uri_low;}