Reputation: 19186
I can do:
curl https://example.com
but not:
curl http://example.com
The difference is only HTTP and HTTPS. Why is that?
How can I make the curl follow the redirect to HTTPS without me have to modify the URL manually? CURLOPT_FOLLOWLOCATION => true,
doesn't work.
Upvotes: 0
Views: 1864
Reputation: 12937
curl
does not follow redirect without -L
option. It looks like the website link you shared has some kind of rewritRule
to rewrite http
pages to https
and hence you get not found error when you curl
.
If there is no rewriteRule
for http
, then only you will be able to curl
url.
If you want to use http
for a https
site, you can use
curl -L "http://example.com"
-L
follows redirect.
Alternatively you can also write this in php:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
where $ch = curl_init();
Upvotes: 1