diff --git a/dyndns.pl b/dyndns.pl
index f65e286..6668555 100755
--- a/dyndns.pl
+++ b/dyndns.pl
@@ -417,7 +417,7 @@ foreach my $d (@DNSDomain) {
         if ($d <0) { $d = join('.', splice(@{[ split(/\./, $cgi->virtual_host) ]}, $d)); }
         else { $d = join('.', splice(@{[ split(/\./, $host) ]}, ($d) ? -$d : 1)); }
     }
-    $dnsdomain = $d if ($host && length($host) == length($d)+rindex($host,$d));
+    $dnsdomain = $d if (!$host || length($host) == length($d)+rindex($host,$d));
     last if $dnsdomain;
 }
 fail($PE, "No host name to act on specified", 400)