0

I have a SSL certificate for non www URL: https://example.com

I know there are many similar question, but none of them seems to solve my problem. Here is what I am trying to do:

Problem:

1) http://www.example.com -> https://example.com **www to non www DONE**

2) http://example.com -> https://example.com **http to https DONE**

So far, my .htaccess file looks like so:

# www to non www
# http to https
# SSL off
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^http\.(.*)$ [NC]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# https://www to https://

Does anyone know the solution? With the current solution, I only get the following error message from the browser:

Corrupted Content Error

The site at http://example.com/ has experienced a network protocol violation that cannot be repaired.

The page you are trying to view cannot be shown because an error in the data transmission was detected.

Please contact the website owners to inform them of this problem.

Here are the solutions that I already tried:

Premox
  • 323
  • 10
  • 25

1 Answers1

0

Change your rules to this:

<IfModule mod_rewrite.c>
    RewriteEngine on

    # https://www and http://www to https://non-www
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule (.*) https://example.com/$1 [R=301,L]

    # http://non-www to https://non-www
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://example.com/$1 [R=301,L]

</IfModule>
JarekBaran
  • 1,311
  • 2
  • 7
  • 12
  • I now have the following error `The page isn’t redirecting properly`. It looks like he's trying 21 times to pass me on. I use FireFox. Chrome says `example.com redirected you too many times.` as error. What is wrong? – Premox Aug 12 '19 at 07:18