Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am using Lighttpd with a snipped i've found on the net. How to redirect all subdomains of a given domain to https without touching other domains or subdomains of domains?

Currently i am doing this on the needed subdomains:

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

I would love to have it the over way around. Is it possible? Can anyone tell me how?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

If I understand right, you'd want to take, say, example.com and redirect not for example.com, but for all of its subdomains?

This should do it:

$HTTP["host"] =~ "^(.*\.example\.com)$" {
  url.redirect = ( "^/(.*)" => "https://%1/$1" )
}
share|improve this answer
    
Thanks allot. example.com could have been included, but i don't really need it. So your snippet fits perfectly! Thanks –  rugar Feb 25 '12 at 20:07
    
sadly i can't do +1 yet :( –  rugar Feb 25 '12 at 20:08
    
Great! To include example.com, just need to add a question mark to the expression in the right place: ^(.*\.?example\.com)$ –  Shane Madden Feb 25 '12 at 20:26
    
just added this, thanks. –  rugar Feb 25 '12 at 20:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.