Fix order of rewrite rules