301在重定向整个域/捕获全部之前,将NGINX中的特定页面重定向



我在nginx中有数千页至301重定向。我可以使用

来实现这一目标
return 301 https://www.newdomain.com$request_uri;

但是,我想将大约6页重定向到新域上的slug/路径,例如

   location /old-path/ {
   rewrite ^ https://www.newdomain.com/newpath/ permanent;
   }

我已经尝试过,但看不清楚如何首先重定向这6个,然后将所有规则应用于其他所有规则。

目前,我仅使用捕获量全部在旧域上进行重定向,然后在新域上有301个将6个帖子更改为新路径(这6个帖子总计2个重定向(。

我想实现以上6页的重定向,还因为我想将6页之一重定向到新域中的新路径,但它仍然存在,但它仍然存在作为新域上的(新(页面(因此,我需要将其重定向到旧域,而不是在新域上(。

按顺序执行重写模块的指令,因此单独使用rewritereturn指令可以完成整个过程,而无需将它们包裹在location块中。例如:

server {
    ...
    rewrite ^/old-path/ https://www.newdomain.com/newpath/ permanent;
    rewrite ^/...       https://www.newdomain.com/.../     permanent;
    return 301          https://www.newdomain.com$request_uri;
}

如果将rewrite语句包裹在location块中,则return语句也必须包裹在location块中。例如:

location / {
    return 301 https://www.newdomain.com$request_uri;
}
location /old-path/ {
    rewrite ^ https://www.newdomain.com/newpath/ permanent;
}

最新更新