Adding check for redirect response code and perform the redirect if needed