Fix rewriting of URL along with tests.