LoginSignup
9
4

More than 3 years have passed since last update.

curl コマンドで HTTP リダイレクト先の URL を取得する

Posted at

概要

  • curl コマンドで HTTP リダイレクト先の URL を取得する
  • 動作確認環境: curl 7.71.1 + macOS Catalina

使用するオプション

  • -w, --write-out : "%{redirect_url}" を指定してリダイレクト先URLを出力する
  • -s, --silent : サイレントモード。プログレスバーやエラーメッセージを出力しない
  • -o, --output : /dev/null を指定してレスポンスボディを出力しない

実行例

$ curl -w "%{redirect_url}" -s -o /dev/null https://bit.ly/3kmTOkc
https://t.co/yITSBp4ino
$ curl -w "%{redirect_url}" -s -o /dev/null https://t.co/yITSBp4ino
https://qiita.com/niwasawa
$ curl -w "%{redirect_url}" -s -o /dev/null https://qiita.com/niwasawa

参考資料

9
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
4