Use requests's allow_redirects=False parameter instead of checking request.url. Also, fall back on the default shortener expansion using an if check instead of creating a new Shortener for every failed match.