Fix query string infinite redirect. Fixes #1309.