made rewriting of urls more robust