2017-10-19 4584 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