4

I have a 301 set up which redirects http://domain.com to http://www.domain.com (http://www.domain.com$S$Q) but if I browse to https://domain.com I get an SSL error (as it expects www.domain.com).

Is there any way to make it redirect before the browser throws a cert error?

2
  • isn't the cert bound to www.domain.com, therefore using the cert on domain.com is seen as a violation? I dunno, its how I always thought it was...
    – Ripped Off
    Mar 29, 2009 at 17:03
  • Yes. I was hoping to have it redirect the user to www.domain.com before caring about the domain.com cert. As Brad says, this isn't possible. Mar 29, 2009 at 19:25

5 Answers 5

6

Yes, but not how you think.

  • You will need a valid certificate for domain.com
  • You will need domain.com and www.domain.com to have separate public IP addresses

If you can't do that, you're out of luck, unfortunately. You can't use HOST headers to differentiate between the two requests, because that's far too late (thus, separate IP addresses). And unless you have a valid certificate, the browser is going to choke, so you also need the 2nd cert.

There's no way around these requirements, I'm afraid.

0
1

I had exact same requirement like redirect all https://domain.com to https://www.domain.com and also redirect all http to https, here how I achieved and get it working IIS 8.5. I used following code in web.config file:

<system.webServer>
  <!--Maybe some other settings-->
      <rewrite>
          <rules>
              <rule name="http to https" stopProcessing="true">
                  <match url="(.*)" />
                  <conditions>
                      <add input="{HTTPS}" pattern="^OFF$" />
                  </conditions>
                  <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
              </rule>
              <rule name="Redirect to www" patternSyntax="Wildcard" stopProcessing="true">
                 <match url="*" />
                 <conditions>
                   <add input="{HTTP_HOST}" pattern="yourdomainname.com" />
                 </conditions>
                 <action type="Redirect" url="https://www.yourdomainname.com/{R:0}" />
              </rule>
          </rules>
      </rewrite>
  <!--Maybe some other settings-->
</system.webServer>

This worked like charm. Actually I generated above code in web.config by installing "URL Rewrite Module" using Web Platform Installer. After installation I found this module in IIS 8.5 then I added new rules. Hopefully, you can directly write this code in your web.config to get things done.

0

There is a way round it. You can get a single cert for both www.domain.com and domain.com. Then you can use a regular redirect. These multi-domain certificates are generally more expensive though.

0

I setup both domains each with their own conf files, (shared)cert, and separate home dirs then added an html meta refresh in the index.html at domain.com to redirect to www.domain.com. It works but perhaps theres a better way.

0

On the certificate for www.domain.com you will need to add a SAN entry for domain.com. Your issuer will reissue the certificate. The certificate will work for the name once it is added as a SAN to the certificate.

A SAN entry is a Subject Alternative Name. You can add several SANs to a certificate.

Here is more info: https://www.digicert.com/subject-alternative-name.htm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .