I want to know what symbol I can use to refer to any character within the utf8 encoding table for nginx rewriting. I have tried:
我想知道我可以使用什么符号来引用utf8编码表中用于nginx重写的任何字符。我努力了:
rewrite ^/.$ /new-location.html break;
but it seems the "." can only stand for ascii characters, when I tried http://example.com/汉 (a Chinese character), it did not work.
但似乎是“。”只能代表ascii字符,当我尝试http://example.com/汉(一个汉字)时,它不起作用。
This also does not work:
这也行不通:
rewrite ^/([\x00-\xff])$ /new-location.html break;
2 个解决方案
#1
4
From the documentation :
从文档:
However, UTF-8 and Unicode support has to be explicitly enabled; it is not the default. The Unicode tables corre- spond to Unicode release 6.0.0.
但是,必须明确启用UTF-8和Unicode支持;它不是默认值。 Unicode表格与Unicode版本6.0.0相对应。
So you have to enable utf-8 to work :
所以你必须启用utf-8才能工作:
"(*UTF8)^yourregex$"
#2
3
The instruction above tells you to use...
上面的说明告诉你使用......
"(*UTF8)^yourregex$"
but your error message reveals you're using something different...
但是您的错误消息显示您正在使用不同的东西......
"^(*UTF8)/(.)$"
I'm no expert, but it looks like you've been advised to prefix your regex with (*UTF8) but instead you're inserting it after the opening character of your regex.
我不是专家,但看起来你已被建议在你的正则表达式前加上(* UTF8),而是你在你的正则表达式的开头字符之后插入它。
#1
4
From the documentation :
从文档:
However, UTF-8 and Unicode support has to be explicitly enabled; it is not the default. The Unicode tables corre- spond to Unicode release 6.0.0.
但是,必须明确启用UTF-8和Unicode支持;它不是默认值。 Unicode表格与Unicode版本6.0.0相对应。
So you have to enable utf-8 to work :
所以你必须启用utf-8才能工作:
"(*UTF8)^yourregex$"
#2
3
The instruction above tells you to use...
上面的说明告诉你使用......
"(*UTF8)^yourregex$"
but your error message reveals you're using something different...
但是您的错误消息显示您正在使用不同的东西......
"^(*UTF8)/(.)$"
I'm no expert, but it looks like you've been advised to prefix your regex with (*UTF8) but instead you're inserting it after the opening character of your regex.
我不是专家,但看起来你已被建议在你的正则表达式前加上(* UTF8),而是你在你的正则表达式的开头字符之后插入它。