You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Jay Levitt <ja...@jay.fm> on 2005/07/10 04:51:46 UTC
[users@httpd] mod_rewrite, RewriteBase, and .htaccess?
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@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org