Get Redirect URL with cURL
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.
The useful and amazing cURL command line utility allows you to fetch an address and return its final destination 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!
Before we get started, it's worth me spending a brief moment introducing myself to you. My name is Mark (or @integralist if Twitter happens to be your communication tool of choice) and I currently work for BBC News in London England as a principal engineer/tech...
Firefox OS is all over the tech news and for good reason: Mozilla's finally given web developers the platform that they need to create apps the way they've been creating them for years -- with CSS, HTML, and JavaScript. Firefox OS has been rapidly improving...
Without a doubt, my least favorite form element is the SELECT
element. The element is almost unstylable, looks different across platforms, has had inconsistent value access, and disaster that is the result of multiple=true
is, well, a disaster. Needless to say, whenever a developer goes...
I know I've harped on this over and over again but it's important to enhance pages for print. You can do some things using simple CSS but today's post features MooTools and jQuery. We'll be taking the options of a SELECT element and generating...
Follow a URL using JavaScript: https://www.npmjs.com/package/linkfollower