Regular expression - nginx regular expression, how to match not ending with / and not ending with .xml .html .htm
过去多啦不再A梦
过去多啦不再A梦 2017-05-16 17:25:48
0
2
823

need

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;
}

try

My own writing method, but failed:

rewrite ([\/]|.xml|.html?)$ $uri/ permanent;

Question

1)如何才可以实现不以.xml .html /结尾的才重写的正则。
2)如何才可以在正则表达式[]中排除完整的一段单词?

Replenish

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?

过去多啦不再A梦
过去多啦不再A梦

reply all(2)
洪涛

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!