I think you wouldn't want to match *foo.com, only *.foo.com, so the "if" regex needs an (escaped) dot at the end, non?