lighttpd configuration to redirect subdomains

For my NeoInvoice project, all requests to the server's sub-domains are sent right to the main server. This means someone can go to,, etc. Search engines don't like to see duplicate content on web servers, cookies being saved on one sub-domain aren't accessible to another, there are all sorts of problems with this. Down the road we do plan on setting up sub-domains for every company (in which case the application will do redirects, not the server), but in the mean time we want to disable all sub domains (except for www).

Adding this rule to your lighttpd configuration file will redirect all sub-domains to the www. sub-domain. People going to the main domain will also be redirected to the www. sub-domain.

$HTTP["host"] =~ "" {
    $HTTP["host"] != "" {
        url.redirect = (
            "^(.*)$" => "$1",
Thomas Hunter II Avatar

Thomas is the author of Advanced Microservices and is a prolific public speaker with a passion for reducing complex problems into simple language and diagrams. His career includes working at Fortune 50's in the Midwest, co-founding a successful startup, and everything in between.