Has anyone here got Rails working with Apache''s ability to do mass virtual hosting - that is, pointing a wildcard DNS record to the web server, and then using either mod_vhost_alias or mod_rewrite to extract the hostname from the URL and turn that into a directory? I''ve been trying, but I keep running into the problem that the Rails .htaccess expects a simple top-level URL, and mod_rewrite or mod_vhost_alias ends up passing it a directory name. In theory this could be solved by RewriteBase, but that means I have to modify each .htaccess as I create it. -- Jay Levitt | Wellesley, MA | I feel calm. I feel ready. I can only Faster: jay at jay dot fm | conclude that''s because I don''t have a http://www.jay.fm | full grasp of the situation. - Mark Adler
Are you talking about getting that subdomain into the rails app running on domain.tld? If so, then there the subdomains method, which returns an array of current subdomains: http://rails.rubyonrails.com/classes/ActionController/AbstractRequest.html#M000142 -- johan On 7/10/05, Jay Levitt <jay-news-WxwZQdyI2t0@public.gmane.org> wrote:> Has anyone here got Rails working with Apache''s ability to do mass > virtual hosting - that is, pointing a wildcard DNS record to the web > server, and then using either mod_vhost_alias or mod_rewrite to extract > the hostname from the URL and turn that into a directory? > > I''ve been trying, but I keep running into the problem that the Rails > .htaccess expects a simple top-level URL, and mod_rewrite or > mod_vhost_alias ends up passing it a directory name. In theory this > could be solved by RewriteBase, but that means I have to modify each > .htaccess as I create it. > > -- > Jay Levitt | > Wellesley, MA | I feel calm. I feel ready. I can only > Faster: jay at jay dot fm | conclude that''s because I don''t have a > http://www.jay.fm | full grasp of the situation. - Mark Adler > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- http://johansorensen.com http://theexciter.com
In article <6890597405071011435a6d1ce3-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>, johans- Re5JQEeQqe8AvxtiuMwx3w-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org says...> Are you talking about getting that subdomain into the rails app > running on domain.tld?No, this is well before that - the problem is that the .htaccess file that Rails uses assumes it will be passed an URL - e.g., if I go to "http://test.rails.jay.fm/", it''ll be passed "/". But if there''s been directory rewriting done before this, it''ll actually be passed, say, "srv/www/rails/test/public/". This is an Apache problem, not a Rails problem, but I''m wondering if people have found a workaround, since large sites like TextDrive presumably don''t manually edit everyone''s .htaccess for them. -- Jay Levitt | Wellesley, MA | I feel calm. I feel ready. I can only Faster: jay at jay dot fm | conclude that''s because I don''t have a http://www.jay.fm | full grasp of the situation. - Mark Adler
Jay Levitt wrote:> In article <6890597405071011435a6d1ce3-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>, johans- > Re5JQEeQqe8AvxtiuMwx3w-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org says... > >>Are you talking about getting that subdomain into the rails app >>running on domain.tld? > > > No, this is well before that - the problem is that the .htaccess file > that Rails uses assumes it will be passed an URL - e.g., if I go to > "http://test.rails.jay.fm/", it''ll be passed "/". But if there''s been > directory rewriting done before this, it''ll actually be passed, say, > "srv/www/rails/test/public/". This is an Apache problem, not a Rails > problem, but I''m wondering if people have found a workaround, since > large sites like TextDrive presumably don''t manually edit everyone''s > ..htaccess for them.You can set the authorization to a virtual host inside the <Directory /> tags in the apache config. And you can sprawl your virtual host configurations across several files. I have a configuration in one of my virtual hosts that looks similar to... <Directory /var/www/otherdir/cgi-bin/tmp> Order allow,deny Options Indexes AuthType Basic AuthName "Members Only" AuthUserFile /etc/apache/auth/admins Require valid-user </Directory> ScriptAlias /cgi-bin/ "/var/www/otherdir/cgi-bin/" ScriptAliasMatch ^/(temp)/?(.*) /var/www/otherdir/cgi-bin/$1.cgi/$2 ScriptAliasMatch ^/(temp2)/?(.*) /var/www/otherdir/cgi-bin/$1.cgi/$2 I get correct user authorization on the original directory /var/www/otherdir/cgi-bin/tmp despite of the script aliases. This may work the same with rewrites. It should be easy enough to test out. For Apache1.3: http://httpd.apache.org/docs/howto/htaccess.html For Apache2: http://httpd.apache.org/docs-2.0/howto/auth.html Apache themselves even state: "In general, you should never use .htaccess files unless you don''t have access to the main server configuration file. There is, for example, a prevailing misconception that user authentication should always be done in .htaccess files. This is simply not the case. You can put user authentication configurations in the main server configuration, and this is, in fact, the preferred way to do things." HTH, Zach
In article <42D1E804.5050204-aRAREQmnvsAAvxtiuMwx3w@public.gmane.org>, zdennis- aRAREQmnvsAAvxtiuMwx3w-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org says...> You can set the authorization to a virtual host inside the <Directory /> > tags in the apache config. And you can sprawl your virtual host > configurations across several files.I''m not sure where authorization came into this. I''m not talking about any authorization code. I''m simply looking for the ability to say: "Given any subdomain N of rails.jay.fm, as ''n.jay.rails.fm'', have Apache consider DocumentRoot to be ''/srv/www/rails/n/public''". In other words, I don''t want to have to specify a separate VirtualHost for every rails app/subdomain I create. Apache *does* allow this, via both mod_vhost_alias and via simple mod_rewrite rules, but unfortunately, neither pass the URL in the expected fashion down to the .htaccess file, which Rails uses to redirect any URLs into dispatch.fcgi, which then gets the URL to the appropriate controller, etc. -- Jay Levitt | Wellesley, MA | I feel calm. I feel ready. I can only Faster: jay at jay dot fm | conclude that''s because I don''t have a http://www.jay.fm | full grasp of the situation. - Mark Adler
> I''m not sure where authorization came into this. I''m not talking about > any authorization code. I''m simply looking for the ability to say: > > "Given any subdomain N of rails.jay.fm, as ''n.jay.rails.fm'', have Apache > consider DocumentRoot to be ''/srv/www/rails/n/public''". > > In other words, I don''t want to have to specify a separate VirtualHost > for every rails app/subdomain I create. > > Apache *does* allow this, via both mod_vhost_alias and via simple > mod_rewrite rules, but unfortunately, neither pass the URL in the > expected fashion down to the .htaccess file, which Rails uses to > redirect any URLs into dispatch.fcgi, which then gets the URL to the > appropriate controller, etc.If you''re using NameVirtualHost you can just make your rails app the default vhost. Everything else will ''just work'' after that. -- Cheers Koz
In article <ef46c93e050710221659baf61b-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>, koziarski- Re5JQEeQqe8AvxtiuMwx3w-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org says...> If you''re using NameVirtualHost you can just make your rails app the > default vhost. Everything else will ''just work'' after that.Thanks, but again, I''m talking about MULTIPLE rails apps. -- Jay Levitt | Wellesley, MA | I feel calm. I feel ready. I can only Faster: jay at jay dot fm | conclude that''s because I don''t have a http://www.jay.fm | full grasp of the situation. - Mark Adler
Have you tried setting the RewriteBase rule to "srv/www/rails/test/public/" in your .htaccess ? unfortunately I don''t have an environement to test it at the moment, please let it be known if you find the answer ... jean On 7/10/05, Jay Levitt <jay-news-WxwZQdyI2t0@public.gmane.org> wrote:> In article <6890597405071011435a6d1ce3-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>, johans- > Re5JQEeQqe8AvxtiuMwx3w-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org says... > > Are you talking about getting that subdomain into the rails app > > running on domain.tld? > > No, this is well before that - the problem is that the .htaccess file > that Rails uses assumes it will be passed an URL - e.g., if I go to > "http://test.rails.jay.fm/", it''ll be passed "/". But if there''s been > directory rewriting done before this, it''ll actually be passed, say, > "srv/www/rails/test/public/". This is an Apache problem, not a Rails > problem, but I''m wondering if people have found a workaround, since > large sites like TextDrive presumably don''t manually edit everyone''s > .htaccess for them. > > -- > Jay Levitt | > Wellesley, MA | I feel calm. I feel ready. I can only > Faster: jay at jay dot fm | conclude that''s because I don''t have a > http://www.jay.fm | full grasp of the situation. - Mark Adler > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
In article <1262cda005071122153e9e4888-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>, jean.helou- Re5JQEeQqe8AvxtiuMwx3w-XMD5yJDbdMReXY1tMh2IBg@public.gmane.org says...> > Have you tried setting the RewriteBase rule to > "srv/www/rails/test/public/" in your .htaccess ? > unfortunately I don''t have an environement to test it at the moment, > please let it be known if you find the answer ...I''m sure that would work, but I''m trying to find a more generic solution, that doesn''t entail editing .htaccess for each site - otherwise, I could just as easily edit httpd.conf for each site. (Though the .htaccess change at least doesn''t require reloading httpd.) I think we''ve reached what I am calling Levitt''s Non-Answer: If you receive four or more correct solutions to the wrong problem, then the originally posed problem cannot be solved. Ah well. -- Jay Levitt | Wellesley, MA | I feel calm. I feel ready. I can only Faster: jay at jay dot fm | conclude that''s because I don''t have a http://www.jay.fm | full grasp of the situation. - Mark Adler