我如何在 Nginx Web 服务器的重写规则中将大写字母转换为小写字母? [英] How i can translate uppercase to lowercase letters in a rewrite rule in nginx web server?

查看:21
本文介绍了我如何在 Nginx Web 服务器的重写规则中将大写字母转换为小写字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要翻译地址:

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

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

推荐答案

是的,您将需要 perl.如果您使用的是 Ubuntu,请不要使用 apt-get install nginx-full,而是使用 apt-get install nginx-extras,它将具有嵌入式 perl 模块.然后,在您的配置文件中:

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

这篇关于我如何在 Nginx Web 服务器的重写规则中将大写字母转换为小写字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆