I have some domains set up on my Ubuntu server that uses Lighttpd. I have wildcard domains and I want the unused subdomains to return 404 instead of 200 and displaying the regular domain. This problem was brought to my attention because some less experienced search engines (Bing, Baidu, mail.ru) are indexing my site with weird subdomains.

I found my same question asked for Apache here: Wildcard DNS, VirtualHosts on apache2, 404 for unused subdomains

However I haven't found anything for Lighttpd.

I want www.example.com/* to 301 redirect to example.com/* (already setup)

I want allUnsetSubdomains.example.com/* to return 404 so that search engines and people understand it doesn't exist.

Here's the relevant data from my vhost.conf file:

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

# lots of other domains #

$HTTP["host"] =~ "example.com$" {
server.document-root = "/var/www/example.com"
server.errorlog = "/var/log/lighttpd/example.com-error.log"
accesslog.filename = "/var/log/lighttpd/example.com-access.log"
server.error-handler-404 = "/index.php"

# lots more domains #

Ideally I'd like to be able to have a universal rule that all unused subdomains for all domains on the server return 404, much like the www redirect one. I honestly don't understand Lighttpd config files or regex very well.


You can use a little "trick" like shown on devsite.pl.

} else $HTTP["host"] =~ "^something.domain.com$" {
    # ....
} else $HTTP["host"] =~ ".*" {
    url.redirect = ( ".*" => "http://domain.com" )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.