Fixes #1154
(cherry picked from commit 5db9897)
Fixes #1857, #1959, #1978 ---Do not include the header if we want to redirect
(cherry picked from commit 46f3756)