请教个nginx正则替换的问题

本人打算使用nginx的subs_filter进行某些链接或者字符串的替换,但nginx的正则似乎和python之类的正则有点出入。。下面是试过的匹配

location / {
   #目的是将https://*.wikipedia.org替换成http://wiki.example.org

    subs_filter .wikipedia.org .wiki.example.org;#这个只能替换成https://wiki.example.org
 
 #也尝试过 subs_filter https://zh.wikipedia.org http://zh.wiki.example.org 但不行,会变成https://zhhttp://example.org       
}

请问可否详细说说?感谢

阅读 6.3k
1 个回答

subs_filter https://(.*).wikipedia.org http://wiki.example.org ir;
i表示忽略大小写
r 表示前面是正则

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