How to redirect HTTP to HTTPS traffic with .htaccess

Open the .htaccess file in the root of your web and add these rules:

# HTTPS Redirect
RewriteEngine On
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

The “RewriteEngine On” is needed only once in the .htaccess file, so if it’s already present just skip it from this code snippet 😉

Leave a Reply