# How to use link\_to when inside a subdomain

**URL:** <https://www.ruby-forum.com/t/how-to-use-link-to-when-inside-a-subdomain/135508>\
**Category:** Rails\
**Created:** [April 22, 2008, 7:22pm UTC](https://www.ruby-forum.com/t/how-to-use-link-to-when-inside-a-subdomain/135508 "2008-04-22T19:22:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [April 22, 2008, 7:22pm UTC](https://www.ruby-forum.com/t/how-to-use-link-to-when-inside-a-subdomain/135508/1 "2008-04-22T19:22:17Z")

</div>

I recently implemented subdomains in my app which is working well.  
But is there a way to use link\_to that gets you OUT of the subdomain?  
For example, if a user is at [http://foo.mysite.com](http://foo.mysite.com) then

link\_to ‘Sign in’, signin\_path

will link to [http://foo.myste.com/signin](http://foo.myste.com/signin) but I need the link to  
instead point to [http://mysite.com/signin](http://mysite.com/signin).

I tried link\_to “sign in”, signin\_path(:host =\> “[mysite.com](http://mysite.com)”) but no  
luck. Any ideas?

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [April 22, 2008, 8:08pm UTC](https://www.ruby-forum.com/t/how-to-use-link-to-when-inside-a-subdomain/135508/2 "2008-04-22T20:08:18Z")

</div>

This guy did it by patching UrlRewriter:  
[http://s2.diffuse.it/blog/show/49\_Subdomain+routing+with+rails](http://s2.diffuse.it/blog/show/49_Subdomain+routing+with+rails)

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [April 22, 2008, 9:37pm UTC](https://www.ruby-forum.com/t/how-to-use-link-to-when-inside-a-subdomain/135508/3 "2008-04-22T21:37:42Z")

</div>

thanks! i added this as a file in my initializers directory.

module ActionController  
class UrlRewriter  
def rewrite(options = {})  
options[:host] = @request.domain  
rewrite\_url(options)  
end  
end  
end

now signin\_url gives [Myste Online](http://myste.com/signin) but signin\_path still  
gives [http://foo.myste.com/signin](http://foo.myste.com/signin)

Is there a way to fix \_path as well as \_url?

---

<div class="post-metadata">

**Author:** ![vince](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b5e925/32.png) [@vince](https://www.ruby-forum.com/u/vince)\
**Post date:** [April 22, 2008, 10:18pm UTC](https://www.ruby-forum.com/t/how-to-use-link-to-when-inside-a-subdomain/135508/4 "2008-04-22T22:18:18Z")

</div>

> Is there a way to fix \_path as well as \_url?

Sorry, I can’t really help you here - I never used the code myself, I  
only remembered having read that article. From a cursory look, it seems  
to me that rewrite\_url is capable of both, depending on the :only\_path  
parameter, but I am not sure in how far it has a hand in generating the  
URL helpers.

I tried delving a bit further into it, but quite frankly, I still find  
Rails Routing to be somewhat scary stuff 🙂
