Home Correctly write redirect in htaccess to force https and www version of a url

# Correctly write redirect in htaccess to force https and www version of a url

user672
1#
user672 Published in May 21, 2018, 4:57 pm
 This is how I am attempting to force www and HTTPS urls in htaccess right now. RewriteCond %{HTTP_HOST} ^example.com [NC] RewriteRule ^(.*)$https://www.example.com/$1 [R=301,L]  The problem is that this still creates a redirect loop. It first redirects to https://example.com and then redirects to https://www.example.com Is there a way to correctly write this in htaccess so that it redirects to both https and www at the same time eliminating the redirect loop? I have tried many examples that I have found here on stackoverflow and they all render redirect loops. Is this unavoidable? Thanks!
 You need to login account before you can post.
Processed in 0.311621 second(s) , Gzip On .