fix query and pagination rewrite