I would like to know if this code in .htaccess
for forcing SSL and WWW in URL is correct, because with another codes I usually get redirect loop, e.g. RewriteCond %{HTTPS} !=on
and now it works like a charm (suspiciously). Also, is possible to write it better/simplier?
# Force to SSL
RewriteCond %{HTTP:HTTPS} !1
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# Force to WWW
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
9 Force www: is perfect thank you.
My server is Heart Internet and the force SSL for Heart is:
Use this:
I found a mod_rewrite solution that works well for both proxied and unproxied servers.
If you are using CloudFlare, AWS Elastic Load Balancing, Heroku, OpenShift or any other Cloud/PaaS solution and you are experiencing redirect loops with normal HTTPS redirects, try the following snippet instead.
That's a bit simpler.
No need for filling in a domain. This is forcing WWW and HTTPS in any case. This is dealing with subfolder as well.
Sorry for bumping this topic but I just wanted to add a simple solution for search engine visitors.