John Siu Blog

Tech - Business Tool, Personal Toys

Tiny VPS Lighttpd Single Site Multiple Domains

How to configure Lighttpd to handle all the domains the way I want?


I own johnsiu.com, johnsiu.org, johnsiu.info, johnsiu.net and they all point to this server.

That is already setup in dns. But I want all of them, with or with www, redirect to http://johnsiu.com. Lighttpd give you an easy way to do it.

In /etc/lighttpd/lighttpd.conf, I added the following section

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
$HTTP["scheme"] == "http" {

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

    $HTTP["host"] =~ "^(www\.)?johnsiu\.(net|org|info)$" {
        url.redirect  = (
            "^/(.*)" => "http://johnsiu.com/$1",
        )
    }

    $HTTP["host"] =~ "^162\.208\.11\.21$" {
        url.redirect  = (
            "^/(.*)" => "http://johnsiu.com/$1",
        )
    }

}

You can see .com is separated from .net, .org, .info redirection. Why?

That is because I only need to redirect http://www.johnsiu.com to http://johnsiu.com.

I don’t need an infinite loop of http://johnsiu.com to http://johnsiu.com redirection.

John Siu

Update: 2020-08-28
comments powered by Disqus