How to redirect from HTTP to HTTPS using .htaccess file

If you have a SSL Certificate installed on your website, you can automatically redirect all your visitors to the secured version of your website (https) so your information will be encrypted and protected from external threats.

If you don’t know what the .htaccess file is, or how to create one, you must read this blog first:

https://www.thcservers.com/blog/what-ishow-to-create-a-htaccess-file/

In order to redirect from HTTP to HTTPS you will have to add this line to your .htaccess file:

RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don’t put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Click Save.

 

Comments

comments

One thought on “How to redirect from HTTP to HTTPS using .htaccess file

Leave a Reply

Your email address will not be published. Required fields are marked *