I
I
Ivan2022-03-18 22:56:29
Nginx
Ivan, 2022-03-18 22:56:29

How to exclude words in this regular expression?

There is this code in the nginx config:

if (!-f $request_filename ) { rewrite ^([^.\?]*[^/])$ "$1/" permanent; }


It adds a slash to all links. But I need not to all, but to exclude certain words. Those. if they are in the link, do not add a slash (for example: api, admin, storage). How can I do that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2022-03-18
@youmixx

rewrite ^(/(?!api|admin|storage)[^.\?]*[^/])$ "$1/" permanent;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question