4

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

Previously i have the ssl cert for https://www.mydomain.com and it was broke, we register the new ssl for the host https://mydomain.com

In the WHM there is only one ssl host but in the cpanel there are two hosts one is old www.mydomain.com and mydomain.com (Is this effect on the redirection?)

the .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 am getting the security alert always while i type https://www.mydomain.com.

What the mistake that i did here?

Thanks in advance

Pus
  • 799
  • 4
  • 12
  • 35

1 Answers1

-1

What is the mistake here ?

The mistake is that there is no %{HTTPS_HOST} variable. The %{HTTP_HOST} is the request header (Host) that's part of the HTTP protocol. You don't need the 3rd line, what you want to do is check whether or not the request was HTTPS using the %{HTTPS} variable like you're doing in the first condition:

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]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • 1
    Thanks for the reply its great answer but I cannot redirect the "https://www.mydomain.com" to "https://mydomain.com" ohters are fine. The main issue here is, i had the ssl certificate "https://www.mydomain.com" because of server issue the ssl is break and newly install ssl in "http://mydomain.com". Is that be the issue ? What you say? – Pus Apr 11 '13 at 08:52