[users@httpd] mod_rewrite, RewriteBase, and .htaccess?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'm trying to set up a server with Apache 2.0.54 and Ruby on Rails, such 
that I can create a directory /srv/www/rails/xxx and have 
xxx.rails.jay.fm launch the appropriate Rails app, without manually 
creating the VirtualHost.

Rails uses .htaccess to rewrite URLs.  If I had test.rails.jay.fm set up 
as an explicit VirtualHost, I'd set the DocumentRoot to 
/srv/www/rails/test/public.  Inside the public dir is an .htaccess, 
automatically created by Rails, with the following rules:

RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

That works fine with an explicitly created VirtualHost; if I go to 
"http://test.rails.jay.fm";, then the URL passed to .htaccess is "/".

But what I want is dynamic mass virtual hosting.  I tried using 
mod_vhost_alias, but realized that mixing this with mod_rewrite can be 
tricky, so I manually copied the vhost-style rules from the httpd docs:

RewriteEngine on
RewriteMap lowercase int:tolower

RewriteCond ${lowercase:%{SERVER_NAME}} ^(www\.)?[a-z-]+\.rails\.
  jay\.fm$

RewriteRule ^(.+) ${lowercase:%{SERVER_NAME}}$1 [C]
RewriteRule ^(www\.)?([a-z-]+)\.rails\.jay\.fm/(.*) /srv/www/rails/  
  $2/public/$3 

The problem, of course, is that now the URL passed to .htaccess is not 
"/", but "/srv/www/rails/test/public/"; this ends up causing a redirect 
loop.

RewriteBase in the .htaccess would solve this, but that kills the whole 
point of mass virtual hosting; I don't want to have to manually tell 
each .htaccess what its directory name is.

Is there some solution?

-- 
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


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux