Redirect all https://www.mydomain.com to https://mydomain.com using htaccess (2 SSL HOST in cpanel)

I need to redirect one domain. https://www.mydomain.com to https://mydomain.com.I use this .htaccess and it does not work for me.

I used to have an ssl certificate for https://www.mydomain.com, and it was broken, we registered a new ssl for the hosthttps://mydomain.com

There is only one ssl host in WHM, but cpanel has two hosts, one of which is old www.mydomain.comand mydomain.com(does this affect the redirection?)

.htaccess is below.

RewriteEngine on

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ https://mydomain.com/$1 [R=301,L]

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^(.*)$ https://mydomain.com/$1 [R=301,L]

I get a security warning whenever I type https://www.mydomain.com.

What mistake did I make here?

Thanks in advance

+5
source share
1 answer

What is the mistake here?

, %{HTTPS_HOST}. %{HTTP_HOST} - (Host), HTTP. , , , HTTPS %{HTTPS}, :

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule  ^(.*)$ https://mydomain.com/$1 [L,R=301]

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$ [NC]
RewriteRule  ^(.*)$ https://mydomain.com/$1 [L,R=301]
0

All Articles