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

前端 未结 5 1614
鱼传尺愫
鱼传尺愫 2020-12-01 04:57

I need to translate the address:

www.example.com/TEST in ---> www.example.com/test

5条回答
  •  余生分开走
    2020-12-01 05:08

    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;
          }
        ...
    

提交回复
热议问题