fix redirect handling bug