Web-server – Lighttpd: Redirect specific location and sub-locations from HTTP to HTTPS (without using domain name)

httphttpslighttpdredirectweb-server

I would like to redirect a specific section of a website from HTTP:// to HTTPS:// using Lighttpd.

I've been looking at this
Lighttpd wiki entry, but the examples don't work the way I want.

I have two requirements:

  1. No specific domain should be specified in the URL redirection configuration.
    • NOT something like this: "^/(.*)" => "https://www.example.com/secure/"
  2. The redirection should also be applied to sub-items of the location, i.e.
    • http:// hostname/secure => https:// hostname/secure
    • http:// hostname/secure/subdir/file.ext => https:// hostname/secure/file.ext

Best Answer

Actually, one of their examples is a near-perfect match to your requirements - just needs tweaked to only work in the secure directory:

$HTTP["url"] =~ "^/secure/" {
  $HTTP["host"] =~ "(.*)" {
    url.redirect = ( "^/(.*)" => "https://%1/$1" )
  }
}