How to rewrite http url to https
I am using this code in .htaccess but it doesn't work. And no error occurs
RewriteEngine On
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{localhost}%{REQUEST_URI} [R=301,L]
+3
user3853169
source
to share
2 answers
Usage %{localhost}
is a problem as there is no such variable called %{localhost}
.
Try this rule in your root .htaccess or Apache:
RewriteEngine On
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{SERVER_PORT} !=443 [OR]
RewriteCond %{ENV:protossl} !=s [OR]
RewriteCond %{HTTP:X-Forwarded-SSL} !=on [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]
+1
anubhava
source
to share
To have your URL auto-rewritten from http to https, just do this and change domain.com to your domain's domain:
RewriteEngine On
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(.*)$ https://www.domain.com/$1 [r=301,nc,L]
+1
BradM
source
to share