Redirect all subdomains to main domain with lighttpd and regex

djangolighttpdregex

Is it possible to redirect all *.domain.com to my domain.com?

I have been messing around with the Regex but without any luck:

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

$HTTP["host"] =~ “domain\.com" {    
   server.document-root = "/var/www/servers/domain.com/awesomesite"
   accesslog.filename = "/var/www/logs/domain.com/access.log"
   server.errorlog = "/var/www/logs/domain.com/error.log"
   fastcgi.server = (
       ".fcgi" => (
           "main" => (
               # Use host / port instead of socket for TCP fastcgi
               "bin-path" => "/var/www/servers/domain.com/awesomesite/domain.fcgi",
               "socket" => "/tmp/domain.sock",
               "check-local" => "disable",
               )
          ),
    )
    alias.url = (
        "/static/" => "/var/www/servers/domain.com/awesomesite/static/",
    )
    url.rewrite-once = (
        "^(/static.*)$" => "$1",
        "^(/.*)$" => "/domain.fcgi$1",
    )     
}

Basically something goes wrong with this solution as it tends to kill all the files after the training slash that has a dot.

Best Answer

This should do the job, I think:

server_modules = (
                      # your modules
                      "mod_redirect",
                  )

$HTTP["host"] =~ ".*\.example\.com" {
    url.redirect = ( "^/(.*)" => "http://example.com/$1" )
}
Related Topic