LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 09-09-2011, 10:28 PM   #1
decenter
Member
 
Registered: Sep 2011
Distribution: Fedora release 21 (Twenty One)
Posts: 156

Rep: Reputation: 19
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.
 
Old 09-10-2011, 02:45 AM   #2
roberto967
Member
 
Registered: Apr 2011
Location: Cagliari, Italy
Distribution: Slackware64-15.0 multilib
Posts: 117

Rep: Reputation: 36
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']);

Last edited by roberto967; 09-10-2011 at 02:46 AM.
 
Old 09-10-2011, 05:17 AM   #3
zackwasa
Member
 
Registered: Sep 2011
Posts: 52

Rep: Reputation: Disabled
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

Last edited by zackwasa; 01-12-2012 at 12:54 AM.
 
Old 09-10-2011, 05:27 AM   #4
whit3fir3
LQ Newbie
 
Registered: Sep 2011
Posts: 5

Rep: Reputation: Disabled
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.
 
Old 09-13-2011, 10:05 AM   #5
decenter
Member
 
Registered: Sep 2011
Distribution: Fedora release 21 (Twenty One)
Posts: 156

Original Poster
Rep: Reputation: 19
Ok. Thanks.I will better install ssl for www.domain.com too.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] redirect https non-www Apache rahmad Linux - Server 16 10-20-2016 01:18 AM
apache 2.0 https to https redirect struct Linux - Software 1 04-22-2011 05:43 PM
[SOLVED] https and http for one domain name yoachan Linux - Server 4 03-13-2011 06:52 AM
Apache https redirect without-www to with-www alitrix Linux - Server 3 07-24-2008 06:11 AM
one domain on 443 and other on 80 but https on 80 domain need to be stopped majid Linux - General 0 08-30-2006 07:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration