Prevent loop with var overshadowing

Incase of a 3xx redirect the var was being overshowed and ever changed
causing an infinite loop.

Fixes #9480
Fixes #9409
Closes #9409

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>