Fix redirection loop bug