more roboust with custom domains, better URL replacement