remove trailing slash in nginx with some certain c

2019-09-01 15:01发布

问题:

I have the following rewrite rule in my nginx:

rewrite ^/(.*)/$ /$1 permanent;

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?

回答1:

You can use a Negative Lookahead.

^/(?!register)(.*)/$

If you don't want register anywhere between such as /exampleregister/, use the following.

^/(?!.*register)(.*)/$


标签: regex nginx