How to set a rule for a redirect in case of multilingualism?

  • 0
    The site is multilingual, but because of this, there were problems with opening the sitemap (there are several of them). The map is successfully opened by url mysite.my/RU_en_sitemap_16-11-2020.xml but if there is a current language in url - 404, for example mysite.my/ru/RU_en_sitemap_16-11-2020
    I try it, but it doesn't work.
    location ~ ^.*\.xml$ {
        if ($request_uri ~* "([^\/]{3,})\.xml?" ) {
            set  $last_path_component  $1;
            return 301 /$last_path_component;
        }
    }

    Tell me how you can solve this problem?
    Nginx Anonymous, Dec 3, 2020

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




    Or

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

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!