Reputation: 99
I can't understand where the problem is. As suggested by the hosting site i use i have an .htaccess file that allows me to redirect from http to https, and on desktop it seems to work quite well. However on mobile no browser redirects correctly, can someone enlighten me?
This is the content of the htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP:X-Forwarded-Proto} !^https$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
Upvotes: 1
Views: 983
Reputation: 89
A solution could be changing your index.html file into and PHP file. By changing the file extension.
Then add the following lines at the top of the file:
<?php
if (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === "off") {
$location = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $location);
exit;
}
?>
Upvotes: 0
Reputation: 89
Try these lines of code instead.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This does always work for me.
Upvotes: 1