如何在位置中使用空格(%C2%A0)实现Nginx重写规则?
问题描述:
我很难搞清楚如何编写这个Nginx规则来重写URL'http://example.com/test/%C2%A0'到'http://example.com/test'。如何在位置中使用空格(%C2%A0)实现Nginx重写规则?
我已经在我的虚拟主机到目前为止已经试过:
Location http://example.com/test/%C2%A0 {
rewrite ^/.* http://example.com/test permanent;
}
它似乎没有工作,而我重新启动nginx的服务。
由于提前,
答
百分比编码的字符是由location
或rewrite
看到他们的时间解码。但非破坏空间仍然看起来像两个字符。正则表达式语法,可以指定使用他们的十六进制值的字符,例如:
location ~ ^/test/\xc2\xa0$ {
return 301 /test;
}
或者:
rewrite ^/test/\xc2\xa0$ /test permanent;
在你的服务器块中尝试'重写^/test /%C2%A0 http://example.com/test permanent;' – Blkc