If you do not want to follow the redirect, but still want to know which page is redirected (for example, for web crawlers), you can use response.headers['location'] :
response = HTTParty.get('http://httpstat.us/301', follow_redirects: false) if response.code >= 300 && response.code < 400 redirect_url = response.headers['location'] end
source share