Redirect to https on lighttpd

lighttpd

Trying to understand how to make the redirect to redirect all http traffic to https on lighttpd webserver using 301.

For instance http://www.example.com should redirect to https://www.example.com and it should work for all sub pages as it's basically rewrite to https.

Best Answer

After some additional search I found a solution. Added to lighttpd.conf restarted and everything works as expected.

$HTTP["scheme"] == "http" {
# capture vhost name with regex conditiona -> %0 in redirect pattern
# must be the most inner block to the redirect rule
    $HTTP["host"] =~ ".*" {
        url.redirect = (".*" => "https://%0$0")
    }
}