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)如何才可以实现不以.xml .html /结尾的才重写的正则。
2)如何才可以在正则表达式[]中排除完整的一段单词?
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?
PHP中文网2017-05-16 17:27:48
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|/)$
巴扎黑2017-05-16 17:27:48
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.