Pelican plugin for NGINX redirection


When I set out to move Gaige's Pages to a static web generator, chronicled in Gaige's Pages moves to static generation, I stated one of the reasons that I favored Pelican was because it is written in python, which is a language that I'm intimately familiar with.

Not surprisingly, that decision because useful pretty quickly. As I was working on moving the Cartographica Blog from SquareSpace to Pelican, I was having some concern over the redirection method I used in Gaige's Pages, the pelican-alias plugin.

The pelican-alias plugin is a highly useful piece of code, especially if you're going to be placing your pelican site on a server you don't control. The method of redirection is to place a file at the original location and then redirect using HTML. This is effective without propagating multiple copies of your pages in multiple locations (as would be the case if you used a mapping in your web server), however it has two undesirable effects:

  1. It causes a slight browser-induced delay for the HTML reload command to be recognized and executed
  2. It doesn't tell search engines to permanently relocate your pages to their new location

I realized that the problem I was looking to solve was slightly different. In my case, I have complete control over the web server (nginx in my case), and therefore can provide configuration information to it directly, including having it redirect using HTTP 301 and 302 codes.

Furthermore, since I have a fine static blog engine with plugin support written in a language that I am comfortable with, and with plenty of example code, I was able to pull together a pretty simple plugin to create a map from the alias attribute in my blog postings to the final published URI. The result is now available as nginx_alias_map on github.

I'm now running two sites using it and both seem to be performing admirably.

Code is published under the MIT license and pull requests are welcome.