Hello! need help ... When contacting www.domainname.com/novosti/i/single-news, I need to send a visitor to www.domainname.com/news/single-news and put 301 redirects. I do not understand why this is not working:

location /novosti/i { rewrite ^/novosti/i/(.*)/[^/]+$ /news/$1; } 

When using such a pattern, when you go to domainname.com/novosti/i/single-news, it simply transfers to the main page (

  • In fact, the string /novosti/i/single-news does not fall under the regular expression ^/novosti/i/(.*)/[^/]+$ because after /novosti/i/ there is not a single slash, what is required by a regular expression. - aleksandr barakin

1 answer 1

I think that you have a regular season.

 location = /novosti/i/single-news { return 301 $scheme://www.domainname.com/news/single-news; } 

If, after all, you do not have the only address (the question is not entirely clear) is hidden under the address www.domainname.com/novosti/i/single-news, but you need to redirect from / novosti / i / to / news /:

 location /novosti/i/ { rewrite ^/novosti/i/(.*)$ /news/$1 permanent; }