nginx下二级目录怎么写重定向?

有这样形式的URLwww.example.com/abc/1.html
www.example.com/bdc/3.html
www.example.com/utf/2.html
若干个,希望重定向到对应的
test.example.com/abc/1.html
test.example.com/bdc/3.html
test.example.com/utf/2.html

abc,bdc,utf这样的目录是已知固定数量的那几个。

不用root 映射,直接用nginx的rewrite 应该如何写?
这个是我的写法:

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

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

}

不对呢~

阅读 3.8k
2 个回答
location ^~/(abc|bdc|utf)/(*.html) {

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

}

试试这个:

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

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

}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题