需要一個正則表達式,在 nginx 中使用。
如果$uri 不是以/結尾且不以.xml 、.html、.htm 結尾的,才 permanent 到$uri/。
location @rewrite {
rewrite [^\/]$ $uri/ permanent;
rewrite . /index.php?s=$uri&$args last;
}
我自己的寫法,但是失?。?/p>
rewrite ([\/]|.xml|.html?)$ $uri/ permanent;
1)如何才可以實現(xiàn)不以.xml .html /結尾的才重寫的正則。
2)如何才可以在正則表達式[]中排除完整的一段單詞?
我使用了這一句,貌似暫時沒有發(fā)現(xiàn)問題。
rewrite [^\/|\.xml|\.html?]$ $uri/ permanent;
疑問,方括號[]中的不是 a-zA-Z0-9 嗎,也可以寫完整的匹配字符串?
你需要的是 支持 并、交、差 的正則表達式引擎:http://nfabo.cn/p/?p=1280
在nginx中,只能用否定反向環(huán)視: .*(?<!.xml|.html|.htm|/)$
你可以先把這些.html,.htm,.xml結尾的文件rewrite到他們原來的目錄,
剩余的在應用你的重寫規(guī)則就達到了你的這個目的。