Jonotespere
Jonotespere

Reputation: 23

htaccess redirect from non-www with https to www with https

I hope this is not a duplicated question, but i can't find the answer to my question. I'm already using an http to https htaccess redirect, which is as follows:

RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

This resolves almost any case, except this one: if i call this URL:


https://domain.com


The result is a page with an invalid certificate issue, which is correct because i only have bought certificates for domains with the "www".

My question is: is there a way to create an htaccess redirect from https://domain.com to https with "www"? Or the only solution is buying certificates also for non-www domains?

As an additional note, i specify that we are running a multi-domain website.

Thank you!

Upvotes: 0

Views: 67

Answers (1)

Tom
Tom

Reputation: 4826

Changing your configuration to add the redirect https://example.com => https://www.example.com will not fully solve your problem :

The browser will connect to https://example.com and show the certificate error before getting the redirect information.

You must create a certificate (buy or use let's encrypt for example) for the non-www domain.

Upvotes: 1

Related Questions