user3227262
user3227262

Reputation: 583

Apache redirect from http to https

I have a small issue,

I am working on an apache2 server where I have to redirect all http requests to https.

Here is code i have written in VH's conf file

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Its seems to be working fine with no issues at all.

Now, the problem is that, we also have an mobile app communicating with our server. This mobile app is communicating over a REST based POST API. The mobile app already in play store and still communicates with our server over HTTP only. Now, because of this redirection set, the server redirects the mobile request to Https, but fails to pass the POST parameters. Can any one suggest me a solution here? Is there any way I can only redirect web requests and let the requests coming from mobile comunicate over http only. Need help and suggestions.

Upvotes: 1

Views: 219

Answers (1)

anubhava
anubhava

Reputation: 786051

You can ignore POST method from your http->https redirections:

RewriteEngine On

RewriteCond %{REQUEST_METHOD} !POST
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Upvotes: 3

Related Questions