Forum: Ruby on Rails action.controller.domain instead of dmn/cntrlr/action ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ffc7ad4d377ee3917a307ebd32c4c090?d=identicon&s=25 Gustav P. (s04015)
on 2006-02-19 21:11
Hey,

I want my users to be able to use the following notation:

  -- http://id.action.controller.domain.com/

instead of having to type in the standard Rails:

  -- http://domain.com/controller/action/id

How can I do this? Is it even possible? If not, don't you think this is
something that the core team should have a look at?

(PS. I'm using MySQL for backend and developed using RAILS v1.0 )
Lots of thanks!!!

Gustav Paul
gustav@psychohistorian.org
Jim Cheetham (Guest)
on 2006-02-19 21:50
(Received via mailing list)
On Sun, Feb 19, 2006 at 09:11:19PM +0100, gustav paul wrote:
> I want my users to be able to use the following notation:
>   -- http://id.action.controller.domain.com/
>
> instead of having to type in the standard Rails:
>   -- http://domain.com/controller/action/id

A rewrite by your webserver would do this.

You need to provide wildcards entries for DNS and the webserver to even
get started, and then use mod_rewrite to change the host name into a
host+url. Read the mod_rewrite docs, lookinf for "Virtual User Hosts"
examples.
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
http://httpd.apache.org/docs/2.0/rewrite/rewrite_guide.html

An untested suggestion would be ...
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+\.[^.]+\.domain\.com$
RewriteRule ^([^.]+)\.([^.]+)\.([^.]+)\.domain\.com(.*)
http://domain.com/$3/$2/$1

-jim
This topic is locked and can not be replied to.