2017-10-19 4582 views
1

我很难搞清楚如何编写这个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的服务。

由于提前,

+0

在你的服务器块中尝试'重写^/test /%C2%A0 http://example.com/test permanent;' – Blkc

回答

0

百分比编码的字符是由locationrewrite看到他们的时间解码。但非破坏空间仍然看起来像两个字符。正则表达式语法,可以指定使用他们的十六进制值的字符,例如:

location ~ ^/test/\xc2\xa0$ { 
    return 301 /test; 
} 

或者:

rewrite ^/test/\xc2\xa0$ /test permanent; 

更多见the location directivethe rewrite directive