Fixed the rewrite (non apache) function