Preserve keys when sorting parameters when generatings urls

Otherwise invalid urls will be generated.

~~This fixes #8375 for me but I'm not sure if this is the only issue.~~
After some more testing I still have that issue, PR is still valid though

cc @tanghus @schiesbn @LukasReschke