Search code examples
pythonwordpressnginxnikola

Nginx: Mapping WordPress URLs to new static website


I am currently moving my blog from a WordPress site that used the URL scheme:

http://www.domainname.com/<YEAR>/<MONTH>/<ARTICLE_SLUG> 

To a static blog site built with Nikola that uses the following URL scheme:

http://www.domainname.com/posts/<ARTICLE_SLUG> 

The original WordPress scheme had built a little bit of Google juice over the years and I would like keep harnessing that. I use Nginx as my web server. Is there a simple way for Nginx to map all the old URLs to the new URLs via configuration. I was thinking that the ngx_http_map_module Nginx Module is the most likely candidate, but I wanted to get a second opinion.


Solution

  • Should work. Just put a location block in your server config similar to this

    location ~ "^/[\d]{4}/[\d]{2}/(.*)$"   {return 301 $scheme://$host/posts/$1;}