0

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.

2
  • You should match $HTTP["host"] == "domain.com", or use an anchored regex, as otherwise it will first rewrite and then redirect the rewritten url.
    – Stefan
    Mar 14, 2014 at 8:22
  • @stefan, could you kindly make an answer with your proposal, as i am not completely sure i understand you. I have made an additional question, hence something goes wrong in the redirect: serverfault.com/questions/581947/…
    – JavaCake
    Mar 14, 2014 at 9:04

1 Answer 1

2

This should do the job, I think:

server_modules = (
                      # your modules
                      "mod_redirect",
                  )

$HTTP["host"] =~ ".*\.example\.com" {
    url.redirect = ( "^/(.*)" => "http://example.com/$1" )
}
9
  • Something is wrong, its looping my $HTTP["host"] =~ "domain\.com" {
    – JavaCake
    Mar 13, 2014 at 14:47
  • And i get bad request with subdomains xxx.domain.com
    – JavaCake
    Mar 13, 2014 at 14:52
  • Updated with an explicit reference to mod_redirect, and tested on a simple host. Should be OK now.
    – user9565
    Mar 13, 2014 at 15:00
  • I tried this, its still looping. for some reason..
    – JavaCake
    Mar 13, 2014 at 15:07
  • It seem to be redirecting, but when it redirects from a subdomain it breaks my aliases for some reason. I dont understand why. The previous problem was for some reason my caching.
    – JavaCake
    Mar 13, 2014 at 15:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .