Solved

.htaccess redirect for ssl

Posted on 2009-07-06
12
600 Views
Last Modified: 2012-05-07
I have a client who has her certificate at http://domainname.com.

There is already some .htaccess code that will redirect if someone comes in via http://www.... and redirect it to the non www version.

However, this does not work for someone who pre-types in httpS://www.domainname.com   This throws a "certificate invalid" error.

Anyone know how to fix this?   I've been banging my head against it all day.
Options +FollowSymLinks 

RewriteEngine on 

RewriteCond %{HTTP_HOST} ^www.mydomain.com

RewriteRule (.*)$ http://mydomain.com/$1 [L,R=301]

Open in new window

0
Comment
Question by:expert-marglar
  • 5
  • 4
  • 2
  • +1
12 Comments
 

Expert Comment

by:tang199
Comment Utility
I just had the do the same thing, and used this:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
0
 
LVL 4

Expert Comment

by:nasserd
Comment Utility
What "tang199" said =)
0
 

Author Comment

by:expert-marglar
Comment Utility
Thanks Tang199.

So, this will prevent the site from allowing a https://www.mydomain.com/xxxx  from being loaded and will instead redirect to https://mydomain.com/xxx?


0
 

Author Comment

by:expert-marglar
Comment Utility
Ok, I tried it but it doesn't do what I need.   What it does is force an http connection over to an https..  not quite what I was looking for.

If I type in a www. before the domain name, I still get the invalid certificate error which is what I'm trying to get rid of.
0
 

Expert Comment

by:tang199
Comment Utility
Expert-Marglar -  this will do is check if the url is using SSL, if not it will simply redirect it to the same url using SSL. Apparently I misunderstood your questions, I apologize. I will look into it a bit further and get back to you ASAP.
0
 

Expert Comment

by:tang199
Comment Utility
Expert-Marglar - Try this, this should do the trick: obviously change the 'thedomain.com' to the domain you are referring to.

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

RewriteCond %{HTTPS} =on
REwriteCond %{HTTP_HOST} =www.thedomain.com
RewriteRule ^(.*) https://thedomain.com/%{REQUEST_URI}
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 

Expert Comment

by:tang199
Comment Utility
that one works, but gives you an extra // - try this:

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

RewriteCond %{HTTPS} =on
REwriteCond %{HTTP_HOST} =www.thedomain.com
RewriteRule ^(.*) https://thedomain.com%{REQUEST_URI}
0
 

Author Comment

by:expert-marglar
Comment Utility
hmmm.   Thanks a million for all of this help, however it still isn't working for me.

If I go to the domain name without www in it, its fine.  It all goes to https.  That is great.

If I put the domain name in with www in it, I get the invalid certificate error.

any ideas?
0
 
LVL 27

Accepted Solution

by:
caterham_www earned 500 total points
Comment Utility
> If I put the domain name in with www in it, I get the invalid certificate error.

You can't change that; impossible; unless your certificate does match the www subdomain, too (some sort of a wildcard certificate). The certificate exchange happens prior the "normal" HTTP request is being send by the browser to the server. That's when your browser issues the domain name mismatch warning. It's impossible to reply with a HTTP response (here: redirect) prior the certificate exchange.
0
 

Author Comment

by:expert-marglar
Comment Utility
Darn!  I was afraid that this was going to be the answer.

Is it possible to have multiple certificates?

Or, can I set up www. to be a separate sub-domain and then forward it to the non www?
0
 

Expert Comment

by:tang199
Comment Utility
You should just get a wildcard cert
0
 
LVL 27

Expert Comment

by:caterham_www
Comment Utility
> Is it possible to have multiple certificates?

Only one per IP. Hence either you have two IPs (and two certificates and a DNS routing non-www -> IP A, www IP -> B) or a wildcard certificate. That is a protocol limitation.

> Or, can I set up www. to be a separate sub-domain and then forward it to the non www?

That's what your rule in your 1st posting does. If you create a different virtualhost (but the same IP) or a ServerAlias and a RewriteRule within one vhost doesn't matter.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ProxyPass - Problem 5 104
XAMPP 14 40
Could you suggest how to deal with  AH00124 Apache error? 10 108
Problem with .htaccess file 4 57
Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now