Project

General

Profile

[Solved] Redirecting http to https for multiple domains

Added by darklurker over 4 years ago

Hi all,

I have two domains running on one server, each domain has its own public IP. HTTPS is working fine, but I can't get http to properly redirect to https. Somewhere in the docs or forums here, I found the suggestion to use

$HTTP["scheme"] == "http" {
$HTTP["host"] =~ ".*" {
url.redirect = (".*" => "https://%0$0")
}
}

But that doesn't seem to work. Is that still the best way to do the redirects? If so, I'll keep looking for errors elsewhere in my config.

I'm running lighttpd 1.4.47 on CentOS 6.10

Thanks for any help.
Dave


Replies (4)

RE: Redirecting http to https for multiple domains - Added by gstrauss over 4 years ago

$SERVER["socket"] == "*:80" {
  $HTTP["host"] =~ ".*" {
     url.redirect = (".*" => "https://%0$0")
  }
}

In lighttpd 1.4.50 and later:

$SERVER["socket"] == "*:80" {
  url.redirect = ("" => "https://${url.authority}${url.path}${qsa}")
}

RE: Redirecting http to https for multiple domains - Added by darklurker over 4 years ago

Thanks, I'll try that. Should the first line have a "==" instead of just an "="?

RE: Redirecting http to https for multiple domains - Added by gstrauss over 4 years ago

Yes. I fixed the example above.

RE: Redirecting http to https for multiple domains - Added by darklurker over 4 years ago

Actually, I think the "Scheme" method works fine. I think my error was that I didn't have
$SERVER["socket"] == "x.x.x.x:80" {
...
}

conditionals for both sites. I put one in for both sites, and as far as I can determine, the redirection with $HTTP["scheme"] is working.

(Web browsers sure don't make troubleshooting this stuff easy, since they want to hide the http/https and the server name in the address bar, not to mention doing strange things when the the HTTPS stuff doesn't come from the server just right, or secretly rendering a cached https:// version of the site even though you specified to use http:// and they can't even actually get to the http site.)

Thanks for helping me with this.
Dave

    (1-4/4)