nginx 重写:任何 UTF8 字符的符号

yan*_*ang 3 regex web-services nginx url-rewriting

我想知道我可以使用什么符号来引用 utf8 编码表中的任何字符以进行 nginx 重写。我试过了:

rewrite ^/.$ /new-location.html break;
Run Code Online (Sandbox Code Playgroud)

但似乎是“。” 只能代表 ascii 字符,当我尝试http://example.com /? (一个汉字),它没有用。

这也不起作用:

rewrite ^/([\x00-\xff])$ /new-location.html break;
Run Code Online (Sandbox Code Playgroud)

Fai*_*Dev 5

从文档:

但是,必须明确启用 UTF-8 和 Unicode 支持;它不是默认值。Unicode 表对应于 Unicode 版本 6.0.0。

所以你必须启用 utf-8 才能工作:

"(*UTF8)^yourregex$"
Run Code Online (Sandbox Code Playgroud)