Apache: .htaccess redirect from HTTP to HTTPS.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule ^.*$ https://%1/$1 [R=301,L]

OR

RewriteEngine on
RewriteCondition %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L] 

OR

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

OR

RewriteEngine On
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://www.odesk.by/$1 [R,L]

OR

If you’re using a load balancer you’ll need to use a different conditional. This works for AWS ELB:


    RewriteEngine On
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule (.*) https://www.odesk.by/$1 [R=301,L]

Scroll to top