How to rewrite URL in HTTPS?

How can I redirect a url like https://mydomain.com to https://www.mydomain.com with only a www.mydomain.com SSL cert from within Rails?

  • Currently, browsers are detecting the https:http://mydomain.com does not have a valid cert.

  • Answer:

    For bulletproof approach you need 2 certificates, each on its own IP address: http://mydomain.com http://www.mydomain.com Alternatively you can get UCC (Unified Communications Certificate) certificate for http://www.mydomain.com that includes http://mydomain.com in SAN (Subject Alternate Name) field, this way you won't need second IP address but will loose a bit of compatibility with ancient browsers. Or you can get normal certificate from Certificate Authority that automatically include your naked domain as Subject Alternate Name in certificate. One of such authorities is StartSSL, from Israel (http://www.startssl.com), where you can get basic domain control validated certificate for free.

Myroslav Opyr at Quora Visit the source

Was this solution helpful to you?

Other answers

I don't think you can get around this, the validation of the certificate happens before the request reaches Rails. Try getting a certificate with a asterisk (*) to the left of the Common Name. So *http://.mydomain.com. This way you can have all subdomains covered. Ex. http://www.mydomain.com http://mydomain.com http://sub.mydomain.com

Guille Carlos

The only viable option to do it is the answer of Myroslav Opyr. It make no sense of being able to use a http://www.mydomain.com certificate for http://mydomain.com . It make no sense because SSL is not only used to encrypt but also to authenticate .... ie : this one is the real one. so changing of identity is obviously blocked.

Antoine Rodriguez

Hi, Actually to comment on the above most CAs now include both www and the root domain name as a SAN field in their regular SSL Certificate offerings when you request one chained to http://www.mydomain.com .  You do not need a SAN or Wildcard SSL Certificate anymore to accomplish what you are trying to do. My recommendation would be to get 1 SSL Certificate with the common name of http://www.mydomain.com and it will include a SAN entry automatically for http://mydomain.com so you can then install the same certificate for both https://mydomain.com and https://www.mydomain.com/ so you can 301 the non www to the www version. Thank You,

Eric Holtzman

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.