# Get subdomain in localhost

**URL:** <https://www.ruby-forum.com/t/get-subdomain-in-localhost/160253>\
**Category:** Rails\
**Created:** [February 13, 2009, 12:32pm UTC](https://www.ruby-forum.com/t/get-subdomain-in-localhost/160253 "2009-02-13T12:32:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![srinathbtech](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7bcc69/32.png) [@srinathbtech](https://www.ruby-forum.com/u/srinathbtech)\
**Post date:** [February 13, 2009, 12:32pm UTC](https://www.ruby-forum.com/t/get-subdomain-in-localhost/160253/1 "2009-02-13T12:32:16Z")

</div>

Hi,  
I was wondering how to get subdomain name in my localhost.  
I’m on ubuntu and set domainnames in /etc/hosts like this

127.0.0.1 : localhost  
127.0.0.1 : tokyo  
127.0.0.1 : sub.tokyo

when i was using puts request.domain it was showing “tokyo” when hit URL  
with [http://tokyo:3002](http://tokyo:3002) and “sub.tokyo” when hit URL with  
[http://sub.tokyo:3002](http://sub.tokyo:3002)

then, how i can i differ subdomains in sub.tokyo  
i tried using request.subdomains.first, but showing nil in localhost

Finaly i was looking for these when used  
puts request.domain.inspect  
===\> “localhost” or “tokyo”  
puts request.subdomains.first  
===\> “sub”

any help??

thanks,  
sri…

---

<div class="post-metadata">

**Author:** ![srinathbtech](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7bcc69/32.png) [@srinathbtech](https://www.ruby-forum.com/u/srinathbtech)\
**Post date:** [February 13, 2009, 3:26pm UTC](https://www.ruby-forum.com/t/get-subdomain-in-localhost/160253/2 "2009-02-13T15:26:18Z")

</div>

This might help you out.

[http://www.robbyonrails.com/articles/2009/01/11/subdomain-accounts-with-ruby-on-rails-explained](http://www.robbyonrails.com/articles/2009/01/11/subdomain-accounts-with-ruby-on-rails-explained)

Cheers,  
Robby

On Fri, Feb 13, 2009 at 3:32 AM, Srinath A.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> with [http://tokyo:3002](http://tokyo:3002) and “sub.tokyo” when hit URL with  
> ===\> “sub”
> 
> any help??
> 
> ## thanks, sri…
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
Robby R.  
Chief Evangelist, Partner

PLANET ARGON, LLC  
design // development // hosting w/Ruby on Rails

> **[Planet Argon](https://www.planetargon.com/)**
>
> Planet Argon is a Ruby on Rails development agency specializing in maintenance and support for existing Rails apps. Based in Portland, OR, Planet Argon has been a member of the Rails community since 2004.

[http://robbyonrails.com/](http://robbyonrails.com/)  
[http://twitter.com/planetargon](http://twitter.com/planetargon)  
aim: planetargon

+1 503 445 2457  
+1 877 55 ARGON [toll free]  
+1 815 642 4068 [fax]
