You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Jay Levitt <ja...@jay.fm> on 2005/08/21 17:16:14 UTC

Fixing RewriteBase/.htaccess incompatibility

Ruby on Rails uses a standard .htaccess file to capture and rewrite URLs.  If
you manually create a VirtualHost for it, everything works fine; point your
browser at the top level of the DocumentRoot, and the .htaccess file sees "/" as
the URL.

However, if you try to do mass virtual hosting, either with mod_vhost_alias or
with manual mod_rewrite rules, the full local pathname is passed to .htaccess,
instead of the DocumentRoot-adjusted URL.  

I'd be happy to submit a patch, but I'm not sure of the Right Way to fix it.  At
first glance, the options I see are (a) modify the "passthrough" option to work
with .htaccess, or (b) create a new "passthrough-htaccess" that does this
instead.  Which I guess leads to the question of whether the current passthrough
behavior is considered broken, or merely suboptimal for this particular case...

Has anyone given this thought before?  I'm sure this comes up a lot with mass
virtual hosting of apps using pre-written .htaccess files.

Jay Levitt

PS - The following are the actual rules that conflict.  In my ideal world, they
would result in the url "foo.rails.jay.fm/bar" pointing at
/srv/www/rails/foo/public/bar, with the .htaccess in /srv/www/rails/foo/public
seeing "/bar" as the URL passed in.

----------
Rails .htaccess:

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

----------
httpd.conf:

<VirtualHost *:80>
ServerName rails.jay.fm
ServerAlias *.rails.jay.fm
UseCanonicalName off
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 
</VirtualHost>