Issue #14132, Issue #17214: Merge two redirect handling fixes from 3.5