Requires a regular expression, used in nginx.
If $uri does not end with / and does not end with .xml, .html, or .htm, it will be permanent to $uri/.
location @rewrite {
rewrite [^\/]$ $uri/ permanent;
rewrite . /index.php?s=$uri&$args last;
}
My own writing method, but failed:
rewrite ([\/]|.xml|.html?)$ $uri/ permanent;
1)如何才可以實(shí)現(xiàn)不以.xml .html /結(jié)尾的才重寫(xiě)的正則。
2)如何才可以在正則表達(dá)式[]中排除完整的一段單詞?
I used this sentence, and it seems that no problem has been found for the time being.
rewrite [^\/|\.xml|\.html?]$ $uri/ permanent;
Question, isn’t a-zA-Z0-9 in the square brackets []? Can you also write a complete matching string?
What you need is a regular expression engine that supports union, intersection, and difference: http://nfabo.cn/p/?p=1280
In nginx, you can only use negation to reverse look around: .*(?<!.xml|.html|.htm|/)$
You can rewrite these files ending in .html, .htm, and .xml to their original directories first,
The rest is achieved by applying your rewrite rules.