HowToRedirectHttpToHttps » History » Revision 24
Revision 23 (gstrauss, 2019-02-22 01:34) → Revision 24/33 (gstrauss, 2020-05-20 05:25)
h1. How to redirect HTTP requests to HTTPS Since 1.4.19 the following should work. For older versions check the history of this page... or just update, srsly. h1. Example 1 - redirect everything lighttpd 1.4.50 or later may use: <pre> $HTTP["scheme"] == "http" { url.redirect = ("" => "https://${url.authority}${url.path}${qsa}") } </pre> Earlier versions of lighttpd 1.4.x may use: <pre> $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") } } </pre> h2. Example 2 - specific url lighttpd 1.4.50 or later may also use: <pre> $HTTP["scheme"] == "http" { url.redirect = ("^/phpmyadmin/" ("" => "https://${url.authority}${url.path}${qsa}") } </pre> Earlier versions of lighttpd 1.4.x may use: h2. Example 2 - specific url <pre> $HTTP["scheme"] == "http" { $HTTP["host"] =~ ".*" { url.redirect = ("^/phpmyadmin/.*" => "https://%0$0") } } </pre> lighttpd 1.4.50 or later may also use: <pre> $HTTP["scheme"] == "http" { url.redirect = ("^/phpmyadmin/" => "https://${url.authority}${url.path}${qsa}") } </pre> h2. Example 3 - only for specific vhost and url <pre> $HTTP["scheme"] == "http" { $HTTP["host"] == "sth.example.com" { url.redirect = ("^/phpmyadmin/.*" => "https://sth.example.com$0") } } </pre> h2. Further stuff Also works the other way round (https -> http) with @if $HTTP["scheme"] == "https"@