S
S
Sergey Erin2020-11-19 11:39:53
Nginx
Sergey Erin, 2020-11-19 11:39:53

How to set a redirect rule for multilingualism?

The site is multilingual, but because of this, there were problems with opening the site map (there are several of them). The map is successfully opened by url, mysite.my/RU_ru_sitemap_16-11-2020.xmlbut if the current language is present in the url - 404, for example mysite.my/ru/RU_ru_sitemap_16-11-2020
I try this, but it does not work

location ~ ^.*\.xml$ {
    if ($request_uri ~* "([^\/]{3,})\.xml?" ) {
        set  $last_path_component  $1;
        return 301 /$last_path_component;
    }
}

Tell me, how can I solve this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-11-19
@artalexs

rewrite "^/[a-z]{2}/(\w+_sitemap_[\d-]+)" /$1.xml permanent;

Or
location ~ "^/[a-z]{2}/(\w+_sitemap_[\d-]+)" {
    return 301 /$1.xml;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question