Fix preserving URI query string. Closes gh-534.

@mehcode @molily ping