linux - 重定向 curl 后获取最终 URL

我需要在页面重定向后获取最终 URL,最好使用 curl 或 wget。

例如 http://google.com 可能会重定向到 http://www.google.com .

内容很容易获得(例如 curl --max-redirs 10 http://google.com -L),但我只对最终 url 感兴趣(在前案例 http://www.google.com )。

有没有办法只使用 Linux 内置工具来做到这一点? (仅限命令行)

最佳答案

curl-w option而子变量 url_effective 就是你 正在寻找。

类似

curl -Ls -o /dev/null -w %{url_effective} http://google.com

更多信息

-L         Follow redirects
-s         Silent mode. Don't output anything
-o FILE    Write output to <file> instead of stdout
-w FORMAT  What to output after completion

更多

您可能想添加 -I (即大写的 i),这将使命令不下载任何“正文”,但它也使用 HEAD 方法,这不是问题包含的内容,并且可能会更改服务器可以。有时服务器对 HEAD 的响应不佳,即使它们对 GET 响应良好。

https://stackoverflow.com/questions/3074288/

相关文章:

linux - 命令行参数中的 "-"(破折号)有什么魔力?

python - APT 命令行界面,类似于是/否输入?

linux - 如何在shell中处理10多个参数

python - 重新加载模块给出 NameError : name 'reload' is not

linux - 如何反汇编原始 16 位 x86 机器代码?

python - 为什么 Python 的原始字符串文字不能以单个反斜杠结尾?

python - 解析 .py 文件,读取 AST,修改它,然后写回修改后的源代码

python - 字符串和字节字符串有什么区别?

regexp)": what d">python - 命名正则表达式组 "(?Pregexp)": what d

bash - 试图在 Bash 的变量中嵌入换行符