Setting up jesred to perform redirects for our midgard site

When you use midgard you loose the ability to use apache to perform redirects for your site as the midgard module deals with any urls relating to hosts that it has in its database. While we had set up redirects using a php script:

173: $redirect_array["woodlands"]="/campaigns/landclearing/";

174: $redirect_array["yellabinna"]="/campaigns/outback/yellabinna/";

175:

176:

177: foreach($redirect_array as $key=>$value) {

178:

179: if (strtolower($argv[0]) == strtolower($key)) {

180: $redirect_string="Location: ".$value;

181: echo $redirect_string."
";

182: header ($redirect_string);

183: exit();

184: }

185: }

186: ?>

it only worked for links going straight from our main page and I wanted something that was as easy to use as apache redirects. As we are using Squid as a reverse proxy for our site getting squid to perform the redirects seemed like a good approach and might well be more efficient that doing it using php in midgard. There are number of specially designed redirectors for squid and you can even just use a simple perl script to perform redirects. The one I chose to use was Jesred which you can easily install using apt on Debian systems. The steps involved in setting it up where:

  1. Create the /var/log/squid directory and set it to be owned by the proxy user.
  2. Install the jesred package.
  3. Edit the /etc/jesred.acl file and uncomment the 0.0.0.0/0 line so that all connections
    will be rewritten.
  4. Edit the /etc/jesred.conf file and turn on the rewrite logging so I can keep track of
    what redirects are being used.
  5. Edit the /etc/jesred.rules file and replace the default rules with the rules I needed.
  6. Edit the /usr/local/squid/etc/squid.conf file and enable the redirector_program.

The rules for the regular expression pattern
matching that jesred uses are the same as squirm and you can see them at
http://squirm.foote.com.au/#squirm_patterns it uses the regex pattern matching from GNU's
regex C library.

The two rules I have in place are:

regex ^http://(www.)?wilderness.org.au/campaigns/yellabinna*
http://www.wilderness.org.au/campaigns/outback/yellabinna
regex ^http://(www.)?wilderness.org.au/campaigns/land%20clearing/nsw/lcupdate_nsw*
http://www.wilderness.org.au/campaigns/landclearing/nsw/lcupdate_nsw