I have seen many articles on rewrites. All good. But none covering this exact situation. So here is my question: hope you can help. Because I cannot get it to work.
- we run website on domain.com (non-www)
- we have ssl set up (so https only)
- we have 1 certificate for the non-www version (not www version)
When we execute all four test cases, 3 are OK, 1 not
Question: Now why is number 4 giving me this error. I would expect the first rule to pick-up and send us to the non-www version. And how do I fix this?
Appreciate any help ;P Sean
This is my currect htaccess
<IfModule mod_rewrite.c> RewriteEngine on # Redirect www to non-www first # Added based on article RewriteCond %{HTTP_HOST} ^www\.(.+) [NC] RewriteRule ^(.*) [R=301,NE,L] # Then redirect http to https (if necessary) RewriteCond %{HTTPS} !=on RewriteRule ^/?(.*) [R=301,L] </IfModule> 102 Answers
You can use this in your .htaccess:
<IfModule mod_rewrite.c> RewriteEngine on # Redirect www to non-www first RewriteCond %{HTTP_HOST} ^www\.(.+) [NC] RewriteRule ^(.*) [R=301,NE,L] # Then redirect http to https (if necessary) RewriteCond %{HTTPS} off RewriteRule ^ [NE,L,R=301] </IfModule> But there's nothing you can do for certificate error.
Read: Redirecting to - without seeing certificate error, possible?
This is not possible to solve only by htaccess or nginx conf.
One needs a certificate to cover both the www and non www version of the domain
So a wildcard cert or a multidomain cert where both www and non www are included as a separate domain
Hope it helps