Rahmi Tuna
Rahmi Tuna

Reputation: 33

Redirect All Requests to Https with 'www'

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.

Upvotes: 0

Views: 88

Answers (1)

Rahmi Tuna
Rahmi Tuna

Reputation: 33

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.

Upvotes: 1

Related Questions