nginx 301 redirect after changing structure of url

I have this blog (wordpress…) and i changed its permalinks in the follwoing way:

OLD : http://www.example.com/2015/05/04/my-post
NEW: http://www.example.com/my-post

Read More

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?? any other solutions will be highly appreciated ..thx

Related posts

1 comment

  1. You need this rewrite statement somewhere in your nginx configuration:

    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.

    See this document for more.

Comments are closed.