0
在Nginx中,如何在重寫規則中的問號之前添加尾部斜槓?Nginx重寫規則:在問號前添加尾部斜槓
我已成功在URL的末尾添加斜槓。一個如下:
http://test/xx --> http://test/xx/
但我不能實現在問號前添加尾部斜槓。具體如下:
http://test/xx?id=2 --> http://test/xx/?id=2
我已經試過如下:
server {
listen 34044;
# add trailing slash to url end
rewrite ^([^.\?]*[^/])$ $1/ permanent;
# add trailing slash before question mark
rewrite "^(.*)([^/]{1})\?(.*)$" $1$2/?$3 permanent;
location/{
...
}
}
不過,這並不問號前加斜槓。
我想,我有一個錯誤在第二個正則表達式,但我看不到它。請幫助
'?'標記查詢字符串的開始,該字符串不是'location'和'rewrite'指令中使用的規範化URI的一部分。有關詳細信息,請參閱[本文檔](http://nginx.org/en/docs/http/request_processing.html)。因此任何尾隨的'/'總是在'''之前。 –
啊!現在我明白了,非常感謝!回答我自己的問題..;) – daniilyar