Nginx 重定向不会捕获 URI

Nginx 重定向不会捕获 URI

基本上我想要以下重定向:

 oldwebsite.com/thehub > new.website.com (currently works but gives me new.website/?)
 oldwebsite.com/thehub/ > new.website.com (currently works but gives me new.website/?)

注意,我希望它们能够在带有斜线和不带有斜线的情况下/thehub/工作/thehub

而且,我希望这能够发生,这是核心问题。

oldwebsite.com/thehub/investors/any-article-here > new.website.com/investors/any-article-here
oldwebsite.com/thehub/something-here > new.website.com/something-here
 location ~ /thehub/(.*)$ {
        rewrite ^ https://new.website.com/$2 permanent;
    } 

答案1

您的正则表达式中只有一个捕获组,其内容将放置在$1变量中,而不是$2。您不需要整个location块来进行此重定向,只需使用

rewrite ^/thehub(?:/(.*))?$ https://new.website.com/$1 permanent;

在任何location块之外。

相关内容