0

I have certificate for www.example.com

It's working for now.

I want to redirect all requests with 'www' and non 'www' to https with 'www'

  1. http://www.example.com to https://www.example.com
  2. http://example.com to https://www.example.com
  3. https://example.com to https://www.example.com

I am getting error that, 'Certificate is only valid for www.example.com'

How can i make redirections?

What i tried?

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

It's working on chrome. On firefox https://example.com is giving error that.

Your connection isn't secure.

I tried to clear history and cache for firefox. It's quite same.

Rahmi Tuna
  • 33
  • 1
  • 8
  • 2
    cert warning cannot be fixed by redirect rules. – anubhava Nov 19 '17 at 16:40
  • it's working on chrome and chrome mobile, it doesn't work on firefox and samsung mobile. – Rahmi Tuna Nov 19 '17 at 16:47
  • Is this a self certified certificate? Depending on the Encryption level and the version of your browser, one browser might accept a certification while the other will not. For instance, IE 11 will take a 1024 bit encrypted certificate while FireFox and Chrome will say the certificate is insecure. – SteveB Nov 19 '17 at 16:49
  • 1
    To remove the cert warning, You need to buy a valid certificate for your non-www domain. Read more on this link https://stackoverflow.com/a/27673113/3160747 – Amit Verma Nov 19 '17 at 16:59
  • I use letsencrypt. And it's secured. Created new certifcate for non www. Now it is giving error for https :// www.example.com – Rahmi Tuna Nov 19 '17 at 17:11

1 Answers1

1

I found the solution.

Generated 1 certificate for 2 domains example.com and www.example.com

https://gethttpsforfree.com/

Followed instruction at here. Used that in .htaccess

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

And yay yay. All variants are working for all browsers including mobile.

Rahmi Tuna
  • 33
  • 1
  • 8