Get final URL after curl is redirected

前端 未结 11 1991
清酒与你
清酒与你 2020-12-04 07:38

I need to get the final URL after a page redirect preferably with curl or wget.

For example http://google.com may redirect to http://www.google.com

11条回答
  •  孤街浪徒
    2020-12-04 08:02

    Thank you. I ended up implementing your suggestions: curl -i + grep

    curl -i http://google.com -L | egrep -A 10 '301 Moved Permanently|302 Found' | grep 'Location' | awk -F': ' '{print $2}' | tail -1
    

    Returns blank if the website doesn't redirect, but that's good enough for me as it works on consecutive redirections.

    Could be buggy, but at a glance it works ok.

提交回复
热议问题