lighttpd将http:// www重定向到https:// www

时间:2015-11-25 09:28:22

标签: redirect https lighttpd

我尝试将domain.com重定向到https://www.domain.com

我有以下规则:

$HTTP["host"] =~ "^domain\.com$" {
url.redirect = ( "^/(.*)" => "https://www.domain.com/$1" )
}

适用于http://domain.com - > https://www.domain.com但它不适用于http://www.domain.com

有什么想法吗?

PS:我在conf文件中有其他域名,因此我需要一个仅适用于domain.com的规则。

1 个答案:

答案 0 :(得分:1)

以下内容应该有效:

$SERVER["socket"] == ":80" {
    $HTTP["host"] =~ "^domain\.com$" {
        url.redirect = ( "^/(.*)" => "https://www.domain.com/$1" )
    }
}
$SERVER["socket"] == ":443" {
    $HTTP["host"] =~ "^domain\.com$" {
        url.redirect = ( "^/(.*)" => "https://www.domain.com/$1" )
    }
}

或者你可以使用这样的东西......更适合你的特定设置:

$HTTP["host"] =~ "^domain\.com$" {
    url.redirect = ( "^/(.*)" => "https://www.domain.com/$1" )
}

$HTTP["scheme"] == "http" {
    $HTTP["host"] =~ "^www\.domain\.com$" {
        url.redirect = ( "^/(.*)" => "https://www.domain.com/$1" )
    }
}