Get final URL after curl is redirected

前端 未结 11 1929
清酒与你
清酒与你 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 07:41

    Thanks, that helped me. I made some improvements and wrapped that in a helper script "finalurl":

    #!/bin/bash
    curl $1 -s -L -I -o /dev/null -w '%{url_effective}'
    
    • -o output to /dev/null
    • -I don't actually download, just discover the final URL
    • -s silent mode, no progressbars

    This made it possible to call the command from other scripts like this:

    echo `finalurl http://someurl/`
    

提交回复
热议问题