G
G
gh0st_d0g2020-10-01 09:04:58
Nginx
gh0st_d0g, 2020-10-01 09:04:58

How to set up a redirect in nginx?

There are addresses localhost/catalog/test/element1/ localhost/catalog/test/element2/ for example, you need to redirect to new addresses localhost/catalog/test2/element1/ localhost/catalog/test2/element2/ taking into account all child elements

rewrite ^/catalog/test(.*) /catalog/test2$1 permanent;

For some reason, such a redirect makes a cyclic redirect like localhost/catalog/test2test2test2test2test2

How to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2020-10-01
@gh0st_d0g

The looping happens because the pattern test(.*)matches test2.
Need to fix totest/(.*)

rewrite ^/catalog/test/(.*) /catalog/test2/$1 permanent;

V
Viktor Taran, 2020-10-01
@shambler81

RewriteCond %{REQUEST_URI} !^(.*)/catalog/test2$ 
RewriteRule ^/catalog/test(.*) /catalog/test2$1 [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question