EneTar

Well-Known Member
Dec 19, 2015
156
12
18
Greece
cPanel Access Level
Root Administrator
I 've read that SSL handshaking takes place before rewrite rules in htaccess and I though to use something like

Code:
NameVirtualHost se.rv.er.ip:443
<VirtualHost se.rv.er.ip:443>
   ServerName www.mydomain.tld
   Redirect permanent / https://mydomain.tld/
</VirtualHost>
I've seen some people doing something similar Nginx: redirect non-www to www on https in nginx

and I thought if there is a way to do this in apache. Of course I tried the above code but I'm definitely no expert at this. Does anybody know how to do it?
 

quizknows

Well-Known Member
Oct 20, 2009
1,008
87
78
cPanel Access Level
DataCenter Provider
This is what I use to force https in .htaccess:

Code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,216
463
Hello :)

Most SSL providers allow "non-www" and "www" to work on a default SSL certificate purchased. Is this not the case with your certificate, or are you attempting to redirect between different domain names?

Thank you.
 

EneTar

Well-Known Member
Dec 19, 2015
156
12
18
Greece
cPanel Access Level
Root Administrator
I purchased a multidomain certificate and didn't know that choosing mydomain.com doesn't cover www.mydomain.com. They need $25/domain to cover all the www versions. So I wanted to redirect the traffic from www to non www through https but I suppose this is not going to happen because of the the ssl handshake taking place before the redirects.. I'm not sure if a reverse proxy in the front could help.