Improved rewrite regexs