skip to Main Content

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>

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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;
    }
    ?>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search