Correctly handle query and fragment URL parts

We need to keep these intact and still rewrite the URL.