brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: curl -L with %{url_effective} shows where a redirect chain ends

Curl
~/tips/tip-curl-redirect-final-url

curl -Ls -o /dev/null --max-redirs 5 -w '%{url_effective} (%{num_redirects} hops)\n' http://example.com/

Prints the final URL after following every redirect.

Short links and http-to-https redirects are easy to expand without opening a browser.

curl -Ls -o /dev/null --max-redirs 5 -w '%{url_effective} (%{num_redirects} hops)\n' http://example.com/

-L follows Location headers, and without it curl stops at the first 3xx. %{url_effective} prints the URL of the last request and %{num_redirects} the number of redirects followed. --max-redirs 5 stops redirect loops, since the default limit is 50. By default curl only sends credentials to the first host, and --location-trusted changes that, which I would not use on unknown sites. For a plain check of one hop, drop -L and read the Location header from curl -I instead.

Further reading: curl manual

More Curl tips curl --trace-ascii – https://example.com/ Retry-After: 120 curl -fsS --fail-early \ url = "https://example.com/data/latest.json" curl -4 -s -o /dev/null -w '%{remote_ip} %{http_code}\n' https://example.com/ All Curl tips (71) All topics

Link