A
A
Alexander Pankov2016-03-04 14:53:22
Nginx
Alexander Pankov, 2016-03-04 14:53:22

How to properly set up a redirect in nginx?

Hello.
There is a url
/souvernirs-for-tourists/ELEMENT_CODE/
I need all urls for this section (souvernirs-for-tourists) to look like this
/souvernirs/ELEMENT_CODE/
How to do it?
And why doesn't it work like this?

location /catalog {
  rewrite ^/catalog/souvernirs-for-tourists/(.*)$ http://SITE-NAME/suveniry/$1 permanent;
}

Thanks in advance for your help!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Pankov, 2016-03-09
@PankovAlxndr

It worked like this

location ~* /catalog/souvernirs-dlya-tourists/ {
  rewrite ^/catalog/souvernirs-dlya-tourists(.*)$ /catalog/suveniry$1 permanent;
}

A
Anton B, 2016-03-05
@bigton

location /catalog/souvernirs-for-tourists/ have you tried?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question