Generate correct sort URL if query parameters are present