[Solved] $HTTP["host"] includes port when not on port 80

Added by joperry almost 9 years ago

I have a situation where I'm trying to make lighttpd user-configurable for the ports and I've been running into a problem doing a url redirect from http to https. I was running into problems with the suggested code:

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

it would redirect me to https://domain:8080/... and if I tried making line 2 '$HTTP["host"] =~ "([^:]*):8080" {' it would work with everything but port 80. When I specified port 80, I wouldn't get forced to SSL but if I tried the suggested code it worked fine.

I'm left only guessing here that $HTTP["host"] leaves off the port when you're on port 80 but includes it when you're not on port 80. Is there a good reason for this? It's highly confusing to be getting the result in two different ways, it would seem highly desirable to either always include the port or never include it.

Replies (2)

RE: $HTTP["host"] includes port when not on port 80 - Added by stbuehler almost 9 years ago

Host is just the header as the browser sends it. (ok, trailing dot from hostname gets removed). Check

RE: [Solved] $HTTP["host"] includes port when not on port 80 - Added by gstrauss about 1 year ago

Including :80 on an HTTP request is optional, as is including :443 on an HTTPS request. Since those are the default ports, clients might omit the port. You might change your line 2 regex to have the port as optional: $HTTP["host"] =~ "([^:]+)(:8080)?"