Follow Redirects with cURL
I love playing around with cURL. There's something about loading websites via command line that makes me feel like some type of smug hacker, just like tweeting from command line does.
I recently cURL'd the Google homepage and saw the following:
curl google.com
#<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
#<TITLE>301 Moved</TITLE></HEAD><BODY>
#<H1>301 Moved</H1>
#The document has moved
#<A HREF="http://www.google.com/">here</A>.
#</BODY></HTML>
I found it weird that Google does the initial redirect but I still want to get the source of the Google homepage with cURL, as with any site that may do a redirect without you noticing. Luckily it's just a single flag:
curl -L google.com
#<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="en">...
The -L
flag instructs cURL to follow any redirect so that you reach the eventual endpoint. Those tiny redirects are just noise anyways, right?
![Creating Scrolling Parallax Effects with CSS]()
Introduction
For quite a long time now websites with the so called "parallax" effect have been really popular.
In case you have not heard of this effect, it basically includes different layers of images that are moving in different directions or with different speed. This leads to a...
![Camera and Video Control with HTML5]()
Client-side APIs on mobile and desktop devices are quickly providing the same APIs. Of course our mobile devices got access to some of these APIs first, but those APIs are slowly making their way to the desktop. One of those APIs is the getUserMedia API...
![Creating the Treehouse Frog Animation]()
Before we start, I want to say thank you to David for giving me this awesome opportunity to share this experience with you guys and say that I'm really flattered. I think that CSS animations are really great. When I first learned how CSS...
![Duplicate the jQuery Homepage Tooltips]()
The jQuery homepage has a pretty suave tooltip-like effect as seen below:
The amount of jQuery required to duplicate this effect is next to nothing; in fact, there's more CSS than there is jQuery code! Let's explore how we can duplicate jQuery's tooltip effect.
The HTML
The overall...
Is there a way to do this outside of the command line in PHP?
The curl-lib in PHP offers an option for that:
And if the url is using/forcing https, set this option before executing the curl:
Please don’t do that, unless you really don’t care about the content of the download. It essentially says “Ignore the SSL errors if it’s broken – trust the same as you would an unencrypted URL.”
The data will still be encrypted, but could be coming from a man-in-the-middle, not from where you thing it’s coming from.
The implementation of curl in PHP has an option for that.
See the following link:
http://stackoverflow.com/questions/3519939/make-curl-follow-redirects
if you liked curl, you’ll love lynx..
I hit an issue with not following redirects myself, but this was a download from a GitHub release download that was redirecting to a S3 bucket. Broke a CLI out in the wild…
In this case, I’m not sure it’s noise (to get at your closing question). I was intentionally not following redirects, as one should not expect this to be happening with GitHub downloads…
I have a support ticket in to see what’s up with this very recent change. Maybe it was a DevOops?