30

I need to translate the address:

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

4

6 に答える 6

19

はい、perl が必要になります。Ubuntu を使用している場合は、apt-get install nginx-full の代わりに、perl モジュールが組み込まれた apt-get install nginx-extras を使用します。次に、構成ファイルで次のようにします。

  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;
      }
    ...
于 2012-06-23T15:46:23.010 に答える
10
location /dupa/ {
    set_by_lua $request_uri_low "return ngx.arg[1]:lower()" $request_uri;
    rewrite ^ https://$host$request_uri_low;
}
于 2015-06-01T21:06:48.423 に答える
9

私は埋め込まれたperlを使用して目標を達成することができました:

location ~ [A-Z] {
  perl 'sub { my $r = shift; $r->internal_redirect(lc($r->uri)); }';
}
于 2011-06-16T10:55:32.383 に答える
3
location ~*^/test/ {
  return 301 http://www.example.com/test;
}

場所は、プレフィックス文字列または正規表現のいずれかで定義できます。正規表現は、前に「~*」修飾子 (大文字と小文字を区別しない一致)または「~」修飾子 (大文字と小文字を区別する一致) を付けて指定します。

ソース: http://nginx.org/en/docs/http/ngx_http_core_module.html#location

于 2014-11-28T11:27:08.087 に答える