Redirect http to https with .htaccess

I've recently set up a SSL certificate for one domain and it's somewhat easy if you have the right tutorials, since it depends on what's your setup (Apache, Nginx...)

For my final set up steps I wanted to redirect all incoming traffic to the new and secured https url, to do that after some search this is the best code I could find:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]Code language: JavaScript (javascript)

If you're using WordPress put it at the top, be aware that you probably already have this RewriteEngine On line in your .htaccess files.

Leave a Reply

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