WordPress Nginx Permalinks Rewrite

I have just spent quite a bit of time migrating old permalinks on client’s blog from “Day and Name” permalink structure to “Post name” permalink structure. The website is powered by Nginx webserver and I was looking for a simple WordPress Nginx Permalinks Rewrite that will do this for me. After digging through the Nginx HttpRewriteModule I worked out a solution that redirects “Day and Name” permalinks to “Post name”.

Before applying this WordPress Nginx Permalinks Rewrite you need to make sure you change your permalink structure from “Day and Name” to “POst name” in WordPress dashboard. See the image below:

WordPress Nginx Permalinks Rewrite

WordPress permalinks

Then add the following Nginx rewrite rule in your vhost:

rewrite "/([0-9]{4})/([0-9]{2})/([0-9]{2})/(.*)" $scheme://$server_name/$4 permanent;

Reload your Nginx settings and you should be good.

If you are changing your permalink structure from “Month and Name” to “post name” then you might want to tweak the above rewrite rule to this:

rewrite "/([0-9]{4})/([0-9]{2})/(.*)" $scheme://$server_name/$3 permanent;