I have to redirect my website from https://www.example.com/
to https://website.com/
.
SSL is properly installed on my server.>
Please note that my SSL certificate is issued for website.com and not www.website.com.
That is your main problem. You are never going to be able to redirect from www
to non www
without a valid certificate for www
. The reason is the connection is handled first before the web server processes anything else including any rewrite rules. So when your browser connects to your site using the https protocol, it has to check for a valid certificate because that's the very nature of SSL to make sure the connection is secure. Then once that is done, Apache will process web server rules that you have in place like rewrites. So it can't rewrite from www to non www until the connection is completed correctly. In order for that to happen you also need a certificate for www
as well. The rewrite rules are not the problem.
This topic comes up quite frequently and there is no way around it. That's the nature of SSL/encryption and how it works.
When buying a cert, try not buying just the domain name, because some CA's will only give you that without www. But if you use www.example.com
in your CSR you will get both www.example.com
and example.com
in the same certificate 99% of the time. Then you won't have to worry about this issue. They are stupid cheap so it shouldn't be an issue to get another one. SSls.com has them for 4.99/yr.