# Ssl with subdomains

**URL:** <https://www.ruby-forum.com/t/ssl-with-subdomains/74841>\
**Category:** Rails\
**Created:** [November 7, 2006, 10:58am UTC](https://www.ruby-forum.com/t/ssl-with-subdomains/74841 "2006-11-07T10:58:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lundie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ac8455/32.png) [@lundie](https://www.ruby-forum.com/u/lundie)\
**Post date:** [November 7, 2006, 10:58am UTC](https://www.ruby-forum.com/t/ssl-with-subdomains/74841/1 "2006-11-07T10:58:55Z")

</div>

Hi,

I am writing an application that uses subdomains for the different  
customers that access it. For example [company1.mydomain.com](http://company1.mydomain.com) and  
[company2.mydomain.com](http://company2.mydomain.com).

I need to have portions of the application under ssl. I have attempted  
different ways of doing Including the following code in my  
application.rb:

def redirect\_to\_ssl

```
 @cont = controller_name

 @act = action_name

 if !request.subdomains.first.nil?
   @subdomain = request.subdomains.first + '.'
 else
   @subdomain = ''
 end

 redirect_to

```

“https://#{@subdomain}[dnbformation.com/#{@cont}/#{@act}/#{params[:id]}](http://dnbformation.com/#%7B@cont%7D/#%7B@act%7D/#%7Bparams%5B:id%5D%7D)”  
unless (@request.ssl? or local\_request?)

end

This, however does not work, and i get an error stating that there are  
too many redirects.

What is the best way of accomplishing this. If need be I will make the  
entire site ssl, but I can’t even figure out how to do that in the  
apache.conf because of the subdomains.

Any help would be great!

Thanks!

Ryan

---

<div class="post-metadata">

**Author:** ![lundie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ac8455/32.png) [@lundie](https://www.ruby-forum.com/u/lundie)\
**Post date:** [November 7, 2006, 10:59am UTC](https://www.ruby-forum.com/t/ssl-with-subdomains/74841/2 "2006-11-07T10:59:05Z")

</div>

SSL certificates are typically tied to a specific subdomain. A single  
‘Wildcard’ certificate can handle multiple subdomains, but they’re also  
considerably more expensive.

[https://www.godaddy.com/gdshop/ssl/ssl.asp?se=%2B&ci=1026](https://www.godaddy.com/gdshop/ssl/ssl.asp?se=%2B&ci=1026)

Your easiest option is probably to use a wildcard and make the whole  
site SSL encrypted. I’ve never used wildcards though, so I can’t  
personally vouch for their ease of use.

---

<div class="post-metadata">

**Author:** ![lundie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/ac8455/32.png) [@lundie](https://www.ruby-forum.com/u/lundie)\
**Post date:** [November 7, 2006, 10:59am UTC](https://www.ruby-forum.com/t/ssl-with-subdomains/74841/3 "2006-11-07T10:59:09Z")

</div>

Thanks for the reply!

I have purchased a wild card domain, the issue is though, have either  
apache or my app redirecting to an ssl connection on certain  
actions/pages.

Thanks!
