move url rewriting into php
for better compatibility with nginx