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
- http://domain.com => https://domain.com =>
- http://www.domain.com => https://domain.com => oK
- https://domain.com => OK
- https://www.domain.com => ERROR. Certificate warning not safe
Question: Now why is number 4 https://www 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 http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) https://%1/$1 [R=301,NE,L]
# Then redirect http to https (if necessary)
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
</IfModule>