Fix #228, #327 Infinite loop when self-redirect