How to write redirection in the secondary directory under nginx?

there are several URLwww.example.com/abc/1.html
www.example.com/bdc/3.html
www.example.com/utf/2.html
in this form. You want to redirect to the corresponding
test.example.com/abc/1.html
test.example.com/bdc/3.html
test.example.com/utf/2.html

. Directories such as

abc,bdc,utf are known to have a fixed number.

how should I write the rewrite of nginx directly without root mapping?
this is my way of writing:

location ^~/(abc|bdc|utf)/(*.html) {

   rewrite ^~/*/(*.html)  https://test.example.com/$!  permanent;

}

is it wrong ~

Mar.07,2021

location ^~/(abc|bdc|utf)/(*.html) {

   rewrite ^~/*/(*.html)  https://test.example.com/$request_uri  permanent;

}

try this:

location ^~/(abc|bdc|utf)/(*.html) {

   rewrite ^(.*) https://test.example.com/$1  permanent;

}
Menu