LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   redirect https://www.domain.com to https://domain.com (http://www.linuxquestions.org/questions/linux-server-73/redirect-https-www-domain-com-to-https-domain-com-902230/)

decenter 09-09-2011 11:28 PM

redirect https://www.domain.com to https://domain.com
 
Hi,

I have ssl installed on my site.It works when I browse https:// . But when some one browse https://www.domain.com , it gives invalid certificate error. So I need to redirect from https://www.domain.com to https://domain.com. Any help is appreciated .

Thanks.

roberto967 09-10-2011 03:45 AM

If you have apache/mod_rewrite installed put this in your .htaccess
Code:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
  RewriteRule ^(.*)$ https://domain.com/$1 [L,R=301]
</IfModule>

Otherwise you can use php in this way:

Code:

if ($_SERVER['HTTP_HOST']=='www.domain.com')
        header("Location: https://domain.com".$_SERVER['REQUEST_URI']);


zackwasa 09-10-2011 06:17 AM

you will get the certificate warning anyway because the mod_rewrite redirect rules are executed after you hit the certificate for https://

unfortunately there's no workaround for this and the only way is to get a certificate for *.yourdomain.com

RMI

whit3fir3 09-10-2011 06:27 AM

zackwasa is correct that using the rewrite rule will not fix issue as people will still have to connect to the server via HTTPS to get the rewrite rule. There is a way to get more than 1 CN assigned to a single SSL certificate. So for example a single SSL certificate would work for both domain.com and www.domain.com. I don't remember the process for this off hand, but you will probably have to generate a new key / csr and send that to your signer and have them resign the cert.

decenter 09-13-2011 11:05 AM

Ok. Thanks.I will better install ssl for www.domain.com too.


All times are GMT -5. The time now is 01:17 AM.