Q:

Lighttpd regex to redirect all pages matching a pattern except for one

Using lighttpd I'm successfully redirecting all pages that begin with:
http://www.domain.com/cgi-bin/MDM/

to the corresponding secure version using this:
$HTTP["scheme"] == "http" {
   $HTTP["host"] == "www.domain.com" {
   url.redirect = ( "^/cgi-bin/MDM/(.*)" => "https://www.domain.com/$1" )
   }
}

and this works great. But now I've discovered one such page can't be served as HTTPS because of a 3rd party script that links to non-HTTPS elements. So I want to exclude that one page which is:
http://www.domain.com/cgi-bin/MDM/page.html

I've tried a number of things but can't seem to cook up the right rule. Any thoughts would be appreciated.

A:

You could use != to exclude any URLs from redirecting:
$HTTP["scheme"] == "http" {
  $HTTP["host"] == "www.domain.com" {
    $HTTP["url"] != "/cgi-bin/MDM/page.html" {
      url.redirect = ( "^/cgi-bin/MDM/(.*)" => "https://www.domain.com/$1" )
    }
  }
}

