Tiny VPS Lighttpd Single Site Multiple Domains

Table of Contents

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

$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
Minimize the Effort, Maximize the Effect!
comments powered by Disqus