V
V
VoRoN19992021-08-24 10:59:58
Nginx
VoRoN1999, 2021-08-24 10:59:58

How to write a regular expression for nginx?

Hello. You need to set up a 301 redirect for nginx.
There is an address where name is any value: /test/*name*/test2/
Need to cut: test2/
As a result, it turns out: /test/*name*/

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2021-08-24
@VoRoN1999

location ~ ^/(test/[^/]+)/test2/$ {
    return 301 /$1/;
}

Or
rewrite ^/(test/[^/]+)/test2/$ /$1/ permanent;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question