Rewrite routes logic