tags:

views:

114

answers:

1

Hi Everyone

I would like to redirect several domains to our dotcom address.

The domains have the following extensions:

  • cn
  • jp
  • ch
  • eu
  • fr

www.domain.fr should point to www.domain.com - sub.domain.fr should point to sub.domain.com and the path after the extension should stay intact so that www.domain.fr/foo points to www.domain.com/foo

FR is just an example. It should work for all extensions the way explained. For me, it does not matter wheter we explicitly write (cn|jp|ch|eu|fr) or if set a wildcard.

I tried the following which did not work:

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

Thanks for your help!

A: 

Something's wrong with your regexp. (*) makes no sense whatsoever. I think you're more familiar with glob syntax. Just remember:

* (in glob) === .* (in regexp)

Basically '.' means anything and '*' means zero or more times of that anything. So I guess you want:

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

Note that plain dots need to be escaped '\.' because '.' means any character at all.

Also, remember that in lighttpd syntax, the $HTTP["host"] variable does not contain any path. You do the path extraction in the url.redirect part, not in the $HTTP["host"] part!

slebetman
actually I am not familiar with both.. regex and glob.. that's why I combine them ;)what do you mean with "does not contain any path"? Because I want the www always at the beginning of the domain, the following code worked for me (also with host):$HTTP["host"] =~ "^domain\.com$" { url.redirect = ("^/(.*)" => "http://www.domain.com/$1")}
Marc
I quess your solution does not work as .com is looped endlessly..
Marc