htaccess redirect http to https causes redirect loop

Erfan asked:

I have edited my .htaccess file to redirect any http request to however, this has cause the website to fall in redirect loop. I have looked at the other solutions and compared them however I detected nothing wrong.

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]

If it does help, domain is

My answer:

Your RewriteCond seems to always match, as the HTTPS version redirects back to the HTTPS over and over.

Try this instead:

RewriteCond %{HTTPS} !=on

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.