Add rewrite middleware