Fix for domains that end in dots and simplified logic for rewrite domains.