我在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特定页面
发布评论