Nginx Rewrites

Nginx rewrite rules allows one to specify how URLs have to be redirected.

This is useful when you make changes to your web content which break URLs external sites might still reference, like, for instance, when you move or delete some posts.

Consider, for instance, the following rewrite directive:

server {
      ...
      server_name  ict4g.net www.ict4g.net;

      ...

      rewrite  "/adolfo/spm[0-9]{2}.*$" http://www.spmbook.com/redirected.html;
}

Here, the rewrite rule redirects URLs in the form http://ict4g.net/adolfo/spm[0-9][0-9]/... to http://www.spmbook.com/redirected.html.

This is the rule I use to redirect students trying to access old editions of my Software Project Management course (which used to be published in my home, under spm<YEAR>) to the new dedicated website which hosts all the content related to the course.