Rewrite routes logic (valid version)