OK, I''m really confused as to how this might work/if it''s possible or even if I''m thinking about it right, so I''ll just explain what I''d like to do and you can shoot holes in it. I have an app running that is for properties. Each property has it''s own "website" within my app and a user can tweak the content, it works well, quite pleased so far. So the URLs to a property look like this for the root http://localhost:3000/properties/1/ then http://localhost:3000/properties/1/full_details http://localhost:3000/properties/1/price_list etc. Is it possible for different urls to point to different pages in someway. i.e. www.chalet-yeti.com -> http://localhost:3000/properties/1/ www.chalet-yeti.com/full_details -> http://localhost:3000/properties/1/full_details www.apartment-marie.com -> http://localhost:3000/properties/2/ etc.... Is this possible/advisable/doable in the same rails app (I can''t think how)? In case it matters the app runs under apache and passenger on my server. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-16 10:37 UTC
Re: multiple domain names mapping to different rails app URLs
Anyone done anything like this before? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Luis Saffie
2010-Oct-16 11:16 UTC
Re: multiple domain names mapping to different rails app URLs
You could do this with Apache Look at modrewrite Luis -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-16 11:19 UTC
Re: multiple domain names mapping to different rails app URLs
Luis Saffie wrote in post #954771:> You could do this with Apache > Look at modrewrite > > LuisThanks that''s great. Will it have the flexibility to deal with all the sub pages? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Luis Saffie
2010-Oct-16 11:52 UTC
Re: multiple domain names mapping to different rails app URLs
Yes, it will You''ll want to use wildcards Luis -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-18 08:24 UTC
Re: multiple domain names mapping to different rails app URLs
Thanks for this. I''m about to try and implement it, appreciate this is a little OT, but has anyone got any more tips for me or even a quick example. Just to be clear, I''m using passenger - will that get in the way or also need any configuration? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-18 10:17 UTC
Re: multiple domain names mapping to different rails app URLs
Someone''s suggested that actually using virtual hosts maybe a better way for me to do this? Thoughts? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Luis Saffie
2010-Oct-18 13:29 UTC
Re: multiple domain names mapping to different rails app URLs
Yeah, for this setup it''s recommended to use virtual hosts along with modrewrite So for example you''d have your site like this defined in your apache.conf <VirtualHost *:80> ServerName www.chalet-yeti.com RewriteEngine on RewriteRule ^(.*)$ http://localhost:3000/properties/1/$1 [R] </VirtualHost> <VirtualHost *:80> ServerName www.apartment-marie.com RewriteEngine on RewriteRule ^(.*)$ http://localhost:3000/properties/2/$1 [R] </VirtualHost> I didn''t test if this will work but if it doesn''t, it should be pretty close. The idea is to have anything that goes to chalet-yeti.com go to http://localhost:3000/properties/1 and anything that follows that url, will be appended to the redirect. If this is a bit too complicated, I suggest you do your homework and read about modrewrite some more. http://httpd.apache.org/docs/2.0/misc/rewriteguide.html Luis -- www.saffie.ca -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-18 13:43 UTC
Re: multiple domain names mapping to different rails app URLs
Hi Luis, Thanks for this, I''m getting *really* close I think. That looks fine and I''ve tried - the redirects are taking effect but it''s not quite right. The localhost:3000 part was just on my Mac, now I''m on the server I need to replace that in some way with the root of the rails app - how do I refer to it in a virtualhost tag. Something like this I imagine (obviously not right)... <VirtualHost *:80> ServerName www.apartment-marie.com RewriteEngine on RewriteRule ^(.*)$ APP_ROOT/properties/2/$1 [R] </VirtualHost> I tried simply <VirtualHost *:80> ServerName www.apartment-marie.com RewriteEngine on RewriteRule ^(.*)$ /properties/2/$1 [R] </VirtualHost> But that resulted in a mad loop of redirects ! as did... <VirtualHost *:80> ServerName www.apartment-marie.com RewriteEngine on RewriteRule ^(.*)$ apartment-marie.com/properties/2/$1 [R] </VirtualHost> Just to be clear (if it''s not already), in the end I''m trying to get the resulting url to look like this. http://www.apartment-marie.com/ and http://www.apartment-marie.com/full_details with no mention of property in it. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Oct-18 13:49 UTC
Re: multiple domain names mapping to different rails app URLs
On Oct 18, 2:43 pm, bingo bob <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi Luis, > > Thanks for this, I''m getting *really* close I think. > > That looks fine and I''ve tried - the redirects are taking effect but > it''s not quite right. > > The localhost:3000 part was just on my Mac, now I''m on the server I need > to replace that in some way with the root of the rails app - how do I > refer to it in a virtualhost tag. > > Something like this I imagine (obviously not right)... > > <VirtualHost *:80> > ServerNamewww.apartment-marie.com > RewriteEngine on > RewriteRule ^(.*)$ APP_ROOT/properties/2/$1 [R] > </VirtualHost> > > I tried simply > > <VirtualHost *:80> > ServerNamewww.apartment-marie.com > RewriteEngine on > RewriteRule ^(.*)$ /properties/2/$1 [R] > </VirtualHost> > > But that resulted in a mad loop of redirects ! > > as did... > > <VirtualHost *:80> > ServerNamewww.apartment-marie.com > RewriteEngine on > RewriteRule ^(.*)$ apartment-marie.com/properties/2/$1 [R] > </VirtualHost> > > Just to be clear (if it''s not already), in the end I''m trying to get the > resulting url to look like this.http://www.apartment-marie.com/ > andhttp://www.apartment-marie.com/full_details > with no mention of property in it.Sounds like you only want to redirect someone touching the root of the site, ie rewrite ^/$ not ^.*$. If you want there to be no trace of the property id in the url then you''ll need to do something rails side, probably inspect the host name in the rails and do something with that. Fred> > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Luis Saffie
2010-Oct-18 13:54 UTC
Re: multiple domain names mapping to different rails app URLs
As Fred metioned. Looks like there''s two rewrites here. Only needs to be done from the Apache side and the other from rails (routes.rb) I suggest you get the apache site going before attempting the other rewrite. Luis -- http://www.saffie.ca -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-18 15:11 UTC
Re: multiple domain names mapping to different rails app URLs
totally lost. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Luis Saffie
2010-Oct-18 15:14 UTC
Re: multiple domain names mapping to different rails app URLs
Ok, let''s back up a bit. For now just do the apache rewrite as I mentioned above. I think Fred is right that you need to use ^/$ rather than ^.*$ so your rule would look like RewriteRule ^/$ apartment-marie.com/properties/2/$1 [R] I think that''s it. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-18 15:23 UTC
Re: multiple domain names mapping to different rails app URLs
Thanks for bearing with me. That one didn''t work - close but it gave me a double rendering of the apartment-marie.com bit, something like this... apartment-marie.com/apartment-marie.com/properties bla... so I edited like so (here''s the real file and it''s live if it helps).. This is much better (ignore the silly google api key message, will sort in time) <VirtualHost *:80> ServerName chaletcordee.co.uk # ServerAlias www.chaletcordee.co.uk DocumentRoot /home/rupert/public_html/bookings/public AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript Options +FollowSymLinks RewriteEngine on RewriteRule ^/$ /properties/1/$1 [R] </VirtualHost> ==== So I feel a bit less lost now... try chaletcordee.co.uk in a browser appears to work and sub links are working too, e.g. full_details. does that look right to you so far? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-18 15:29 UTC
Re: multiple domain names mapping to different rails app URLs
So taking it a step on I figure I need to work on a few things... need to make sure www versions all operate ok. need to make sure that when I add another domain, that works to. http://chaletcordee.co.uk/properties/1/comments should be http://chaletcordee.co.uk/comments guess this is the rails part. My routes file is here, not bothered if the nested admin routes need to be acessesed with an ugly URL for now, it''s just the public facing pages that''d be important initially. pastie of my routes file. http://pastie.org/1230080 Fred? :-) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-18 16:51 UTC
Re: multiple domain names mapping to different rails app URLs
I''m half way there then? Need to handle the rest on the rails side - via my routes.rb file? Will this approach work? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Luis Saffie
2010-Oct-18 17:13 UTC
Re: multiple domain names mapping to different rails app URLs
yes, it should work. Look like you may need to add single resources along with the nested ones. Not entirely sure if you can do this though... Luis -- http://www.saffie.ca -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-18 17:27 UTC
Re: multiple domain names mapping to different rails app URLs
Anyone else comment as to if this combination of apache rewrites and rails routing will play nicely together. I''ll try it of course just imagine that it may have been done before by somebody. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Luis Saffie
2010-Oct-18 23:46 UTC
Re: multiple domain names mapping to different rails app URLs
You could do it all with modrewrite. You''ll just need to specify the specific rules and rewrite actions for all your cases. It''s not that hard, just read up on it. There are countless of resources on the web about this. Here''s a starting point http://www.webmastertips.us/tutorials/mod_rewrite.htm http://articles.sitepoint.com/article/guide-url-rewriting I was thinking of writing an article about this on my site but there''s so much out there that it seems pointless. Luis. -- http://www.saffie.ca -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-19 09:43 UTC
Re: multiple domain names mapping to different rails app URLs
Thanks Luis, I''ll refer to them and see if I can find a solution totally via apache/modrewrite; I suspect I can! I need to get a handle on the syntax of those rewrite commands, the command chain and regexes, should be ok. I''ll post back to this thread with the solution when I crack it. You need to wear *many* hats in this game at times, not every problem seems to be solvable in the RoR app itself (or perhaps it is but the *pragmatic* approach for a quick win is to ssh to the server and get funky with with apache config). -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Oct-19 14:13 UTC
Re: multiple domain names mapping to different rails app URLs
bingo bob wrote in post #955373:> Thanks Luis, I''ll refer to them and see if I can find a solution totally > via apache/modrewrite; I suspect I can! I need to get a handle on the > syntax of those rewrite commands, the command chain and regexes, should > be ok. I''ll post back to this thread with the solution when I crack it. > > You need to wear *many* hats in this game at times, not every problem > seems to be solvable in the RoR app itself (or perhaps it is but the > *pragmatic* approach for a quick win is to ssh to the server and get > funky with with apache config).Virtual host names can never be implemented completely within Rails, since it''s up to Apache to dispatch to the correct server instance based on the hostname -- thus, the logic happens before Rails ever sees it. Anything not involving the hostname can (and usually should) be done with Rails routing. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-19 15:25 UTC
Re: multiple domain names mapping to different rails app URLs
Well in my case I need to do two things. 1) redirect www.foo.com => www.foo.com/properties/1/ DONE 2) rewrite the resulting url www.foo.com/properties/1/ => www.foo.com NOT DONE YET I''m clear point 1 should be done in Apache config, as it is. Are you saying point (2) should be done in Apache or Rails (routes.rb). -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Lee Davis
2010-Oct-19 15:41 UTC
Re: Re: multiple domain names mapping to different rails app URLs
You can get www.foo.com/ to display the content of properties/1 by setting your route for "root" in your routes.rb file. In Rails 2, this would be map.root :controller => :properties, :action => :view, :id => 1 Now if you are trying to make property1.foo.com point there as well, that could be done in Apache. What it sounded like you wanted was to point www.foo.com to property/1 and www.bar.com to property/2. Am I mistaken at that point? You can do redirects that fundamentally rewrite the URL from the server''s perspective, without changing what the user sees in their browser''s location bar. So you could avoid the whole routes.rb hack I''ve outlined above by rewriting requests for [www.]foo.com to baz.com/ property/1 [NS,QSA] (those flags keep the URL whatever was written in the browser. Then the user could enter www.foo.com/edit and the request would be www.baz.com/property/1/edit at your server. Walter On Oct 19, 2010, at 11:25 AM, bingo bob wrote:> Well in my case I need to do two things. > > 1) redirect www.foo.com => www.foo.com/properties/1/ > DONE > > 2) rewrite the resulting url www.foo.com/properties/1/ => www.foo.com > NOT DONE YET > > I''m clear point 1 should be done in Apache config, as it is. > Are you saying point (2) should be done in Apache or Rails > (routes.rb). > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails- > talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > . > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > . >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Oct-19 15:56 UTC
Re: multiple domain names mapping to different rails app URLs
Please quote when replying. bingo bob wrote in post #955467:> Well in my case I need to do two things. > > 1) redirect www.foo.com => www.foo.com/properties/1/ > DONE > > 2) rewrite the resulting url www.foo.com/properties/1/ => www.foo.com > NOT DONE YET > > I''m clear point 1 should be done in Apache config, as it is.The way you are describing it here, that should simply be Rails map.root.> Are you saying point (2) should be done in Apache or Rails (routes.rb).I don''t understand your description well enough, but I suspect you''re badly overcomplicating things. I''ve never tried to do multiple subdomains on one Rails app, but off the top of my head, here''s what I''d try first: * Use an Apache/Nginx rewrite to map, say, http://www.foo.com/properties/1/ to http://www.myrailsapp.com/www.foo.com/properties/1 * Within the Rails app, set up the routes to recognize the subdomain parameter: (in Rails 2) map.resources properties, :path_prefix => '':hostname'' * Use params[:hostname] as necessary in your app logic. You *might* be able to do without the Apache rewrite and simply dispatch on request.host , but I don''t know if that would work. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-19 16:21 UTC
Re: Re: multiple domain names mapping to different rails app URLs
Could well be overcomplicating things! Walter''s point here is sounds closest I think - I''ll try it.> You can do redirects that fundamentally rewrite the URL from the > server''s perspective, without changing what the user sees in their > browser''s location bar. So you could avoid the whole routes.rb hack > I''ve outlined above by rewriting requests for [www.]foo.com to baz.com/ > property/1 [NS,QSA] (those flags keep the URL whatever was written in > the browser. Then the user could enter www.foo.com/edit and the > request would be www.baz.com/property/1/edit at your server.As it stands apache modrewrite in place but not finished - working though, :-)! http://www.chaletcordee.co.uk/ as you will witness if you visit this is rewritten to this in the users browser... http://www.chaletcordee.co.uk/properties/1/ Fine, content works but I''d like this to be http://www.chaletcordee.co.uk/ in the users browser in a similar manner http://www.apartmentnicole.co.uk/ goes to http://www.apartmentnicole.co.uk/properties/2/ I''d like this to be http://www.apartmentnicole.co.uk/ in the users browser if you click on the photos page after visiting http://www.chaletcordee.co.uk/ you get here... http://www.chaletcordee.co.uk/properties/1/photos I''d like this to be http://www.chaletcordee.co.uk/photos in the users browser, etc phew - is anyone still reading - I doubt it ! :-). -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Luis Saffie
2010-Oct-19 16:24 UTC
Re: multiple domain names mapping to different rails app URLs
Did you try using the flags Walter suggested, [NS,QSA]? Can you post your Apache rewrite rules? Hopefully we''re not going too off topic with Apache :-) -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-20 21:11 UTC
Re: multiple domain names mapping to different rails app URLs
Luis Saffie wrote in post #955491:> Did you try using the flags Walter suggested, [NS,QSA]? Can you post > your Apache rewrite rules? > > Hopefully we''re not going too off topic with Apache :-)Sorry for delay, currently running with this <VirtualHost *:80> ServerName chaletcordee.co.uk ServerAlias www.chaletcordee.co.uk DocumentRoot /home/rupert/public_html/bookings/public Options +FollowSymLinks RewriteEngine on RewriteRule ^/$ /properties/1/$1 [R] </VirtualHost> <VirtualHost *:80> ServerName apartmentnicole.co.uk ServerAlias www.apartmentnicole.co.uk DocumentRoot /home/rupert/public_html/bookings/public Options +FollowSymLinks RewriteEngine on RewriteRule ^/$ /properties/2/$1 [R] </VirtualHost> Will try [NS,QSA] but from what walter said I think I might need the rewriterule to be different as well, more than just adding those flags? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Walter Lee Davis
2010-Oct-20 21:30 UTC
Re: Re: multiple domain names mapping to different rails app URLs
Do try it, that''s the secret sauce that lets the URL remain masked. The R flag you have there currently is doing a full external redirect to a subfolder, but I don''t think you need that. Walter On Oct 20, 2010, at 5:11 PM, bingo bob wrote:> Will try [NS,QSA] but from what walter said I think I might need the > rewriterule to be different as well, more than just adding those > flags?-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-24 05:40 UTC
Re: multiple domain names mapping to different rails app URLs
Been trying rewrite stuff all week but can''t get to where I want to be. If anyone has an answer or another way - v keen to hear. I did wonder about this...http://github.com/shuber/proxy or my routes.rb file - or more apache tinkering.. this didn''t get me there either (lots of repeated stuff here) http://www.sitepoint.com/forums/showthread.php?t=708145 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-25 07:15 UTC
Re: multiple domain names mapping to different rails app URLs
any tips - I''m not certain that I can achieve this with modrewrite. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I have built something along these lines and here is how it might work for you. Have a domain model that maps a domain name to a property_id(decide whether you are going to use www or no-www (http://no-www.org/) or both if you want but it it is better to choose one or the other for SEO and analytics. so in your application_controller.rb put in some code that effectively does a lookup on the domain model to find your property. before_filter :domain_lookup private def domain_lookup @domain = Domain.find_by_host(request.host) raise DomainNotFound unless @domain # should always find it as you defined it right? raise DomainUnavailable unless @domain.live? # the on button for the domain raise DomainMaintenance if @domain.maintenance? # if you need to pull it down @host = @domain.host + request.port_string # I need this when building some redirects as my setup is more complicated, SSL etc. end Now you have @domain.property available in your application wherever you need it assuming you set up a belongs_to association. Now you can refer to something like @domain.property.photos in your application. I use @domain.css to pick up which of my CSS''s I want to use with that domain. You can have as much as you like in there such as maintenance flags etc. Next decide what your root path is going to be and set map.root accordingly. You may find there is no need to go through the property controller at all for the end-user since the whole domain is about a single property and you define that outside in your seed data or admin console. Now for the virtual host config in Apache. <VirtualHost *:80> # define any of you domains as the servername, it doesn''t matter which one you choose to be the main one (perhaps your admin domain?) ServerName property1.com # list all of the other domains that run against the same rails application remembering to pick up the www''s too and wildcards work too! ServerAlias \ skichalets*.com www.skichalets*.com \ ahouse.com www.ahouse.com \ myshed.com www.myshed.com \ www.property1.com # then I rip off the www. using this rule RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1 [R=301,L] RailsEnv production RailsBaseURI / DocumentRoot /srv/www/vhosts/yourapp/current/public </VirtualHost> Warning if you are using SSL, you can only have one SSL host per IP address. Basically the host name is not available to apache until it has been decrypted by the host certificate, by which time it is too late! I work around this by passing the property_id to the ssl redirects and then use this to look up the domain. Just be careful about rebuilding and building sessions. So the logical flow goes like this: user puts a URL into browser apache picks up the host name and checks to see if it is the list of hosts rips the www off the host name if you want it to send the request to be routes.rb in /srv/www/vhosts/yourapp/current/ config your application_controlller.rb looks up the domain from request.host HTH O. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-25 11:50 UTC
Re: multiple domain names mapping to different rails app URLs
Right - once more unto the breach and all that! Thanks for this, I see what you mean. I''ve part implemented, the bit I don''t quite get relates to finding the relevant property and what I put in the routes file to hook it up (hooking up the default root to a domain/property). The bit you describe here.... "Next decide what your root path is going to be and set map.root accordingly. You may find there is no need to go through the property controller at all for the end-user since the whole domain is about a single property and you define that outside in your seed data or admin console." My complicated (perhaps over) routes.rb is like this at present. http://pastie.org/1230080 Here''s what I have just done in the last hour or so all good as far as it goes I think ! migrated a new Domain model property belongs to domain domain has one property (all hooked up and playing nicely) App controller... before_filter :domain_lookup private def domain_lookup @domain = Domain.find_by_host(request.host) # raises errors when necessary end bit of my header file for testing... Request host is : <%= request.host %> <br/> Set domain in app controller is : <%= @domain.host %> <br/> Property that belongs to this domain is : <%= @domain.property.name %> <hr/> as you can se this test works...the find works nicely.. http://chaletcordee.co.uk/properties/1 http://apartmentnicole.co.uk/properties/2/ apache side...just as you suggested, understood nice and simple (I like the www striping! no-www is interesting) <VirtualHost *:80> ServerName chaletcordee.co.uk ServerAlias www.chaletcordee.co.uk apartmentnicole.co.uk www.apartmentnicole.co.uk # then I rip off the www. using this rule RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1 [R=301,L] RailsEnv production RailsBaseURI / DocumentRoot /home/rupert/public_html/bookings/public </VirtualHost> Stuck on next step! Owain wrote in post #956838:> I have built something along these lines and here is how it might work > for you. > > Have a domain model that maps a domain name to a property_id(decide > whether you are going to use www or no-www (http://no-www.org/) or > both if you want but it it is better to choose one or the other for > SEO and analytics. > > so in your application_controller.rb put in some code that effectively > does a lookup on the domain model to find your property. > > before_filter :domain_lookup > > private > > def domain_lookup > @domain = Domain.find_by_host(request.host) > raise DomainNotFound unless @domain # should always find it as > you defined it right? > raise DomainUnavailable unless @domain.live? # the on button for > the domain > raise DomainMaintenance if @domain.maintenance? # if you need to > pull it down > @host = @domain.host + request.port_string # I need this when > building some redirects as my setup is more complicated, SSL etc. > end > > Now you have @domain.property available in your application wherever > you need it assuming you set up a belongs_to association. Now you can > refer to something like @domain.property.photos in your application. > I use @domain.css to pick up which of my CSS''s I want to use with that > domain. You can have as much as you like in there such as maintenance > flags etc. > > Next decide what your root path is going to be and set map.root > accordingly. You may find there is no need to go through the property > controller at all for the end-user since the whole domain is about a > single property and you define that outside in your seed data or admin > console. > > Now for the virtual host config in Apache. > > <VirtualHost *:80> > # define any of you domains as the servername, it > doesn''t matter which one you choose to be the main one (perhaps your > admin domain?) > ServerName property1.com > # list all of the other domains that run against the > same rails application remembering to pick up the www''s too and > wildcards work too! > ServerAlias \ > skichalets*.com www.skichalets*.com \ > ahouse.com www.ahouse.com \ > myshed.com www.myshed.com \ > www.property1.com > > # then I rip off the www. using this rule > > RewriteEngine On > RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] > RewriteRule ^(.*)$ http://%1 [R=301,L] > > RailsEnv production > RailsBaseURI / > > DocumentRoot /srv/www/vhosts/yourapp/current/public > </VirtualHost> > > Warning if you are using SSL, you can only have one SSL host per IP > address. Basically the host name is not available to apache until it > has been decrypted by the host certificate, by which time it is too > late! I work around this by passing the property_id to the ssl > redirects and then use this to look up the domain. Just be careful > about rebuilding and building sessions. > > So the logical flow goes like this: > > user puts a URL into browser > apache picks up the host name and checks to see if it is the list of > hosts > rips the www off the host name if you want it to > send the request to be routes.rb in /srv/www/vhosts/yourapp/current/ > config > your application_controlller.rb looks up the domain from request.host > > HTH > > O.-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-25 12:00 UTC
Re: multiple domain names mapping to different rails app URLs
or to put it another way... what does your routes.rb look like to get the root urls right for a property (in my case properties anyway). also, totally happy to bypass properties controller for the public views, just figured I''d done it the rails way with a properties controller and separate actions for book / prices / full_details etc. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-26 06:27 UTC
Re: multiple domain names mapping to different rails app URLs
Now I''m firmly back in the rails world here, any kind soul give me a pointer as to how I might finish this one. I figure I need to modify the routes file and perhaps conditionally modify the rails app home root based on domain - what else? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Dhruva Sagar
2010-Oct-26 06:47 UTC
Re: Re: multiple domain names mapping to different rails app URLs
I think you should run different rail apps on different ports and use Nginx to proxy to them. That should be simple enough. -- Thanks & Regards, Dhruva Sagar. On Tue, Oct 26, 2010 at 11:57, bingo bob <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Now I''m firmly back in the rails world here, any kind soul give me a > pointer as to how I might finish this one. I figure I need to modify the > routes file and perhaps conditionally modify the rails app home root > based on domain - what else? > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-26 07:02 UTC
Re: multiple domain names mapping to different rails app URLs
Multiple apps is definitely not what I wish to do here. It''s a single app. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Dhruva Sagar
2010-Oct-26 07:05 UTC
Re: Re: multiple domain names mapping to different rails app URLs
Oh well if that is the case then you can probably check the current domain / request.url in a before_filter inside application_controller and work accordingly thereafter, that should be simple enough too... -- Thanks & Regards, Dhruva Sagar. On Tue, Oct 26, 2010 at 12:32, bingo bob <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Multiple apps is definitely not what I wish to do here. > It''s a single app. > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
A quick look and the following points: - you are not scoping your property_id to the domain. If you go to http://chaletcordee.co.uk/properties/1 you can change to properties 2 in the domain controller and you pick up the other property. Your application controller should set an instance variable for the request @property which you should always use as the parent of all subsequent request in a before filter. I think you said you implemented this. App controller... before_filter :domain_lookup private def domain_lookup @domain = Domain.find_by_host(request.host) # raises errors when necessary end - apache is doing some redirects here. You shouldn''t need any other than the no-www stuff. Take them out. Let rails do the routing. You only really need mod_rewrite if you are doing URL rewriting which I don''t think you need. - your map.root invokes your welcome controller. This should work if the welcome controller index action shows the details of the property you have sitting in your instance variable @property Sounds like you are almost there. O. On Oct 26, 7:27 am, bingo bob <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Now I''m firmly back in the rails world here, any kind soul give me a > pointer as to how I might finish this one. I figure I need to modify the > routes file and perhaps conditionally modify the rails app home root > based on domain - what else? > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-26 08:49 UTC
Re: multiple domain names mapping to different rails app URLs
Inline - I won''t have a chance to test this out until a little later but yes - thanks for this, think I''m getting it. Owain wrote in post #957124:> A quick look and the following points: > > - you are not scoping your property_id to the domain. If you go to > http://chaletcordee.co.uk/properties/1 you can change to properties 2 > in the domain controller and you pick up the other property. Your > application controller should set an instance variable for the request > @property which you should always use as the parent of all subsequent > request in a before filter. I think you said you implemented this. > > App controller... > before_filter :domain_lookup > private > def domain_lookup > @domain = Domain.find_by_host(request.host) > # raises errors when necessary > endSo if I''ve understood you correctly, I''d do something like this...something like I mean - just to see if this is on the right lines? App controller... before_filter :domain_lookup private def domain_lookup @domain = Domain.find_by_host(request.host) # raises errors when necessary # New step find the property and set the instance variable, # do something else sensible if there''s a problem if @domain # guess the line below is the key # set a property instance via the domain name @property = @domain.property else # do stuff if there''s no domain... end properties controller at present I find properties by ID - but with this new method I wouldn''t need to do that, it''s already done in the app controller. should be easy. routes this is where I possibly need most advice. http://pastie.org/1230080 at present these lines... map.photos ''properties/:id/photos'', :controller => ''properties'', :action => ''photos'' map.contacts ''properties/:id/contacts'', :controller => ''properties'', :action => ''contacts'' get me to the various pages, but I do not want the /properties/id bit in the URL, how do I redo this routing without /properties/id showing... is it simply? map.contacts ''/contacts'', :controller => ''properties'', :action => ''contacts''> - apache is doing some redirects here. You shouldn''t need any other > than the no-www stuff. Take them out. Let rails do the routing. You > only really need mod_rewrite if you are doing URL rewriting which I > don''t think you need.OK - I thought I just had the no-www stuff in there - but ok.> > - your map.root invokes your welcome controller. This should work if > the welcome controller index action shows the details of the property > you have sitting in your instance variable @propertyI''ll have to think of a sensible place to point map.root, one this is a front page for the app which isn''t a particular property at all - or I might send it to one of the properties - haven''t registered a domain name for it yet.> Sounds like you are almost there.I think so ! :-).> O.-- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
bingo bob
2010-Oct-26 13:34 UTC
Re: multiple domain names mapping to different rails app URLs
Am I on the right lines ? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
This might be a good time to mention that with the rails 3 redesign, you can specify much more powerful constraints from within the router. Katz''s website has a nice article on it: http://yehudakatz.com/2009/12/26/the-rails-3-router-rack-it-up/ The part I found most interesting was this: Basecamp::Application.routes do constraints(:subdomain => "support") do match "/foo/bar", :to => "foo#bar" end end As it turns out, you can swap :hostname (or :host) into the place of :subdomain and setup different routes for different domains. Using this in combination with some sort of hostname checking in a before_filter is all I needed for my project. No need for any URL rewriting in nginx. Hope that helps. On Oct 19, 9:21 am, bingo bob <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Could well be overcomplicating things! > > Walter''s point here is sounds closest I think - I''ll try it. > > > You can do redirects that fundamentally rewrite the URL from the > > server''s perspective, without changing what the user sees in their > > browser''s location bar. So you could avoid the whole routes.rb hack > > I''ve outlined above by rewriting requests for [www.]foo.com to baz.com/ > > property/1 [NS,QSA] (those flags keep the URL whatever was written in > > the browser. Then the user could enterwww.foo.com/editand the > > request would bewww.baz.com/property/1/editat your server. > > As it stands apache modrewrite in place but not finished - working > though, :-)! > > http://www.chaletcordee.co.uk/ > as you will witness if you visit this is rewritten to this in the users > browser...http://www.chaletcordee.co.uk/properties/1/ > Fine, content works but I''d like this to behttp://www.chaletcordee.co.uk/ > in the users browser > > in a similar manner > > http://www.apartmentnicole.co.uk/ > goes tohttp://www.apartmentnicole.co.uk/properties/2/ > I''d like this to behttp://www.apartmentnicole.co.uk/ > in the users browser > > if you click on the photos page after visitinghttp://www.chaletcordee.co.uk/ > you get here...http://www.chaletcordee.co.uk/properties/1/photos > I''d like this to behttp://www.chaletcordee.co.uk/photos > in the users browser, etc > > phew - is anyone still reading - I doubt it ! :-). > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Oct 26, 9:49 am, bingo bob <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Inline - I won''t have a chance to test this out until a little later but > yes - thanks for this, think I''m getting it.Me too. I was out all day yesterday.>> properties controller > > at present I find properties by ID - but with this new method I wouldn''t > need to do that, it''s already done in the app controller. should be > easy. > > routes > > this is where I possibly need most advice.http://pastie.org/1230080 > > at present these lines... > > map.photos ''properties/:id/photos'', :controller => ''properties'', :action > => ''photos'' > map.contacts ''properties/:id/contacts'', :controller => ''properties'', > :action => ''contacts'' > > get me to the various pages, but I do not want the /properties/id bit in > the URL, how do I redo this routing without /properties/id showing... > > is it simply? > > map.contacts ''/contacts'', :controller => ''properties'', :action => > ''contacts''exactly. since your properties controller already has access to the @domain.property or @property from the before_filter. Therefore no need to pick it up from the params[:id] at all. so you should have a in routes.rb map.root :controller => "properties" this will mean that a call to http://chalet.com will invoke the index action of the properties controller. Your index action should simply call render :action => :details template to show the @domain.property or whatever the template uses. I guess you probably want to have a "master domain" that lists all of the properties and still use the same app. Also for your admin support. Well it is easy to amend your before_filter to handle a non- defined domain and then tweak the index action to render appropriately. if @property render :action => :details else render :action => :index end Your routes do need a bit of cleaning up. In fact you should look RESTful routes. e.g. map.resources :availability I guess you have a pretty big properties controller, try and keep them skinny and delegate the stuff about availability to the availability controller.> > > - apache is doing some redirects here. You shouldn''t need any other > > than the no-www stuff. Take them out. Let rails do the routing. You > > only really need mod_rewrite if you are doing URL rewriting which I > > don''t think you need. > > OK - I thought I just had the no-www stuff in there - but ok. >I was getting a 302 redirect for some reason. Make sure you have removed any of the URL rewriting you were doing. Hope that helps. O. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.