rewrite tag replace code