N
N
NetyNicka2014-12-22 13:56:42
htaccess
NetyNicka, 2014-12-22 13:56:42

How to redirect curl request from http to https?

There is a site with access via http and https
htaccess entry

RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]


When sending a request like
curl --data "[email protected]&password=value2" https://mysite.example/api/authenticate

Everything works perfectly.

If you remove the redirect in htaccess, then the request to mysite.example also works.
But with redirect enabled, the http request throws an error:
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="https://mysite.example/api/authenticate">here</a>
.</p>
<hr>
<address>Apache/2.2.22 (Debian) Server at myserver.example Port 80</address>
</body></html>


Actually the question is, is it possible to somehow fix this situation so that http requests are redirected to https, and not to a 302 error?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vlad Zhivotnev, 2014-12-22
@NetyNicka

This is not an error, this is a valid response status. Errors are 4xx and 5xx.
In general, the curl has an option -L - with it it processes redirects.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question