在某些情况下忽略Nginx中的尾部斜杠 [英] remove trailing slash in nginx with some certain cases ignored
本文介绍了在某些情况下忽略Nginx中的尾部斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的nginx中具有以下重写规则:
I have the following rewrite rule in my nginx:
rewrite ^/(.*)/$ /$1 permanent;
删除任何URL末尾的斜杠.但是我想做一个例外,例如当URL为/register/
时,我不想应用此规则.如何将其放入正则表达式中?
to remove trailing slash at the end of any URL. However I wanted to make an exception such that when the URL is /register/
I don't want this rule to be applied. How do I put that into the regex?
推荐答案
您可以使用负向超前.
^/(?!register)(.*)/$
如果您不希望register
之间的任何地方,例如/exampleregister/
,请使用以下内容.
If you don't want register
anywhere between such as /exampleregister/
, use the following.
^/(?!.*register)(.*)/$
这篇关于在某些情况下忽略Nginx中的尾部斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文