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

编程入门 行业动态 更新时间:2024-10-16 02:27:11
本文介绍了在重定向整个域/全部捕获之前,在Nginx中重定向301特定页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在nginx中有成千上万的页面到301重定向.我可以使用

I have thousands of pages to 301 redirect in nginx. I can achieve this using

return 301 www.newdomain$request_uri;

但是,我想将大约6个页面重定向到新域上已更改的子段/路径,例如

However, there is approximately 6 pages that I would like to redirect to a changed slug/path on the new domain, eg

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

我已经尝试过了,但是看不出如何首先重定向这6个,然后将全部捕获"规则应用于其他所有内容.

I have tried but can't see to work out how to redirect these 6 first, specifically, and then have the catch all rule apply to everything else.

此刻,我仅使用全部捕获功能在旧域上进行重定向,然后在新域上使用301将6个帖子更改为新路径(这6个帖子共2个重定向).

At the moment I am redirecting on the old domain using the catch all only, and then have 301s on the new domain changing the 6 posts to the new paths (2 redirects total for these 6 posts).

我想实现上述目标,不仅是为了将这6个页面的重定向减少到1,而且还因为我想将6个页面之一重定向到新域上的新路径,但是它的旧路径仍然存在也是新域上的(新)页面(因此,我需要将其重定向到旧域上,而不是新域上.)

I would like to achieve the above not only to reduce the redirects to 1 for these 6 pages, but also because I want to redirect one of the 6 pages to a new path on the new domain, but it's old path still exists as a (new) page on the new domain too (therefore I need to redirect it on the old domain, not on the new one).

推荐答案

rewrite模块按顺序执行,因此整个过程可以单独使用rewrite和return指令完成,而无需将它们包装在location块中.例如:

The directives of the rewrite module are executed in order, so the entire process can be accomplished with rewrite and return directives alone, without wrapping them within location blocks. For example:

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

如果将rewrite语句包装在location块内,则return语句也必须包装在location块内.例如:

If you wrap the rewrite statements within location blocks, then the return statement must also be wrapped within a location block. For example:

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

更多推荐

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

本文发布于:2023-10-31 13:53:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546282.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   页面   Nginx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!