[英]nginx 301 redirect after changing structure of url
I have this blog (wordpress...) and i changed its permalinks in the follwoing way: 我有这个博客(wordpress ...),我以以下方式更改了其永久链接:
OLD : http://www.example.com/2015/05/04/my-post
OLD:
http://www.example.com/2015/05/04/my-post
: http://www.example.com/2015/05/04/my-post
NEW: http://www.example.com/my-post
新:
http://www.example.com/my-post
: http://www.example.com/my-post
so i simply removed the date from the link. 所以我只是从链接中删除了日期。 the problem is i have many posts (thousands) published all over the net with the old structure.
问题是我在旧结构的网络上发布了许多帖子(成千上万)。 there are qordpress plugins that allows you to create 301 redirect for a specific request but is there a way in the server level where i can do this 301 redirect without dealing with plugins etc.. the structure is consistent so even though i never worked with regex i guess it can help me here??
有qordpress插件可以让您为特定请求创建301重定向,但是在服务器级别上有没有一种方法可以在不处理插件等的情况下执行301重定向。因此结构是一致的,即使我从未使用过regex我想这可以在这里帮助我? any other solutions will be highly appreciated ..thx
任何其他解决方案将不胜感激..thx
You need this rewrite statement somewhere in your nginx
configuration: 您需要在
nginx
配置中的某处使用以下重写语句:
rewrite "^/\d{4}/\d{2}/\d{2}(/.*)$" $1 permanent;
It is possible to place it inside a location
block, but as that location block would need to use a regular expression too, it would probably save processing if this rewrite is left naked in the server context, that is placed somewhere near the top of your server
block. 可以将其放置在一个
location
块内,但是由于该位置块也需要使用正则表达式,因此如果在服务器上下文中将该重写放在裸露位置(可能位于您的顶部附近),则可能会节省处理时间server
块。
See this document for more. 有关更多信息,请参见此文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.