fix redirect loop bug