What should be the code in .htaccess for redirecting to https version of website from Non-SSL? The website is html based
Yes this is perfect ..... You can add some more like ensure that site is opening with www or without www ...... permanently redirect from http to https etc. Take a look at below code with some additional parameters. Options +FollowSymLinks RewriteEngine on # ensure www. (If prefer without www then remove this section) RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # ensure https RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] Code (markup):
Thanks, this worked well. But for SEO purposes you want to setup a 301 redirect. RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] Code (markup):
It would be more efficient to do the redirect in Cloudflare using their `Always Use HTTPS` and also mean less code for you to maintain. This is available on their free plan and you would also get ddos protection.