# Ssl

**URL:** <https://www.ruby-forum.com/t/ssl/127738>\
**Category:** Rails\
**Created:** [January 31, 2008, 9:09pm UTC](https://www.ruby-forum.com/t/ssl/127738 "2008-01-31T21:09:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 31, 2008, 9:09pm UTC](https://www.ruby-forum.com/t/ssl/127738/1 "2008-01-31T21:09:44Z")

</div>

Hi all,

I have just enabled SSL on my HTTPD installation and it is working  
flawlessly. Even my rails app is working, and I did not change one  
line of code in it.

I access my app trought HTTPS and every link on it keeps the HTTPS as  
protocol.

But the problem is that wherever I use redirect\_to on my app, it  
redirects to HTTP, and not HTTPS. I thought it would use the current  
protocol…

How can I fix that?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 31, 2008, 9:11pm UTC](https://www.ruby-forum.com/t/ssl/127738/2 "2008-01-31T21:11:30Z")

</div>

Adding: I want SSL to be enabled on the whole application, and not  
only on a few actions/controllers. It is already working like that,  
just redirect\_to doesn’t seem to work.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 31, 2008, 9:25pm UTC](https://www.ruby-forum.com/t/ssl/127738/3 "2008-01-31T21:25:43Z")

</div>

My guess is that you’re using url\_for() to redirect and that Rails  
itself isn’t managing the SSL but some other process on your server  
(pound, in our case).

So, for us, and I’m guessing you too, Rails has no idea it’s behind an  
SSL connection. That that means that url\_for generates a http: path  
instead of https:.

If this is all true for you, you can use path\_for instead of url\_for.  
path\_for generates a relative path instead of a full url including the  
protocol, which if linking inside your application, should work fine.  
Another option is to pass the :only\_path =\> true argument to url\_for. A  
third option is to just pass a hash to redirect\_to, such as…

redirect\_to :controller =\> ‘people’, :action =\> ‘show’, :id =\>  
@person.id

And lastly, if you’re using RESTful routes, you can just…

redirect\_to person\_path(@person)

removed\_email\_address@domain.invalid wrote:

> redirects to HTTP, and not HTTPS. I thought it would use the current  
> protocol…
> 
> How can I fix that?
> 
> >

–  
[http://www.5valleys.com/](http://www.5valleys.com/)  
[http://www.workingwithrails.com/person/8078](http://www.workingwithrails.com/person/8078)
