I am wanting my site to always load in https, which I thought I had setup, but apparently, sometimes during redirects my site still loads http.
I currently have the following code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,NE,L]
My host provider sent me a link which shows the following code:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
My question is, should I adopt their method or is there something that I could add to my htaccess code so that all redirects will load as https.
Edit: Does anyone know what this piece of code actually does?
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
This CF-Visitor
this header is a JSON object, containing only one key called “scheme”. The meaning is identical to that of X-Forwarded-Proto above - eg it will be either HTTP or HTTPS, and it is only relevant if you need to enable Flexible SSL in your Cloudflare settings.
So , to check it is better to check weather htpps
setup on the same server or with cloudfare like that :
RewriteEngine On
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"' [OR]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
Note : clear browser cache the test
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.