回答:
を使用してHTMLヘッダーを表示できます-I
。リダイレクトがメタリフレッシュである場合、この方法でヘッダーとしてアップする必要があります。
lamp@oort ~ $ curl -I http://google.com<br>
HTTP/1.1 301 Moved Permanently<br>
Location: http://www.google.com/<br>
Content-Type: text/html; charset=UTF-8<br>
Date: Thu, 21 Nov 2013 14:59:13 GMT<br>
Expires: Sat, 21 Dec 2013 14:59:13 GMT<br>
Cache-Control: public, max-age=2592000<br>
Server: gws<br>
Content-Length: 219<br>
X-XSS-Protection: 1; mode=block<br>
X-Frame-Options: SAMEORIGIN<br>
Alternate-Protocol: 80:quic
PHP経由でリダイレクトが発生している場合は、ブラウザーが移動する場所と実際に移動する場所を比較することでこれを検出できます... Python、JSなどでこれを行う方法はたくさんあります。興味深い1つのプロジェクトあなたにはphantomjs、スクリプト可能なヘッドレスブラウザーです。
からman curl
:
-w, --write-out <format>
Defines what to display on stdout after a completed and
successful operation.
<...>
redirect_url When an HTTP request was made without -L to
follow redirects, this variable will show the
actual URL a redirect would take you to.
(Added in 7.18.2)
したがって、おそらくcurl -w "%{redirect_url}" link1
最初のリダイレクトURLが表示されます。
多分このようなものがあなたのために働く:
URL="http://google.com"
while [ -n "${URL}" ]
do
echo $URL
URL=$(curl -sw "\n\n%{redirect_url}" "${URL}" | tail -n 1)
done