Fix redirection so query strings are not added multiple times

The previous fix caused the query string to be appended twice when a redirection happens. This fixes the problem.