URL redirects can be glorious or annoying depending on which side of them you are on and which side you want to be on. Redirects are helpful for vanity URLs (useful in advertising) but sometimes they're annoying in that they could potentially break your code if you encounter a redirect you weren't anticipating.
URL重定向可能是光荣的还是令人讨厌的,具体取决于您位于重定向的哪一侧以及您希望位于哪一侧。 重定向对有用的URL(在广告中很有用)很有帮助,但有时它们很烦人,因为如果您遇到意外的重定向,它们可能会破坏您的代码。
The useful and amazing cURL command line utility allows you to fetch an address and return its final destination URL:
有用且令人惊奇的cURL命令行实用程序允许您获取地址并返回其最终的目标URL:
# "/css" doesn't exist but WordPress tries to find the closest match
# and then redirects to it ("/css-animation-callback")
curl -Ls -w %{url_effective} -o /dev/null https://davidwalsh.name/css
# Outputs: https://davidwalsh.name/css-animation-callback
The url_effective
variable is what we're after. The L
directive tells cURL to follow redirects, the s
directive tells cURL to be silent (i.e. not output the page contents). You provide the URL, cURL follows it to its endpoint -- easy!
url_effective
变量是我们所追求的。 L
指令告诉cURL跟随重定向, s
指令告诉cURL保持沉默(即不输出页面内容)。 您提供URL,cURL跟随其到达端点-简单!