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.

About Ricard Torres

Senior Front-end Software Engineer at Netcentric, from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

@ricard_dev @ricard_dev

📝 Blog 🎙 Podcast

Leave a Reply

Add <code> Some Code </code> if you need to.

*
*