Refactor the subdomain/hosts rewrite