On Thu, 17 Feb 2005, David Heinemeier Hansson wrote:
>> This brought up a former problem of mine: I was not able to deploy a
>> single rails app to an apache www-root subdirectory, because all the
>> automatically generated links (link_to, actions, etc.) pointed at
>> www.servername.com/action instead of
>> www.servername.com/ochronus/rails_app/action. I couldn''t find
any
>> workaround, and even "googling" was no good... Does anyone
have an
>> idea?
>
> You can use :application_prefix. You can even set this as a default
> rewrite option if all your rewrites needs to be made with this prefix.
> Example:
>
> class ApplicationController
> protected
> def default_url_options(options)
> { :application_prefix => "ochronus/" }
> end
> end
i having luck so far just hacking the .htaccess and have not even had to
modify my rails code. can you commnet on why the .htaccess file is so huge?
i mean what exactly is the grand scheme of it? it seems like it''s
obvious
goal
turning
controller/action
into
dispatch.cgi?controller=controller&action=action
can be accomplished in much fewer lines of code that also does not make rails
links fubar... here is an example of what i''m talking about
a trailing slash is added, but ONLY to those requests that do not contain a
slash, and then this is externally redirected
RewriteRule ^([/_a-zA-Z0-9-]+[^/])$ /$1/ [R]
then the ONLY rule that could ever match it is
RewriteRule ^([-_a-zA-Z0-9]+)/$ ?controller=$1&action=index [QSA,L]
but then this can be matched without adding the trailing slashe in the first
place with
RewriteRule ^([-_a-zA-Z0-9]+)$ ?controller=$1&action=index [QSA,L]
why?
then there is the matter of all the conditions to filter things that that
should NOT be re-written (we are a directory, we have a query string, etc.)
why not the opposite approach: re-write ONLY those things that need to be
re-written. how do we know this? we know that urls that are composed of made
up (non-existent) paths need to be re-written. therefore we guess that the
path components need to be munged into a dispatch query string. so far (30
minutes only since i''ve battled selinux all day - arggh) this is my
approach:
AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI
RewriteEngine On
RewriteBase /cookbook/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/+([^/]+)/+([0-9]+)$
dispatch.cgi?controller=$1&action=$2id=$3 [QSA,L]
RewriteRule ^([^/]+)/+([^/]+)$
dispatch.cgi?controller=$1&action=$2 [QSA,L]
RewriteRule ^([^/]+)$
dispatch.cgi?controller=$1&action=index [QSA,L]
RewriteRule ^([^/]+)/+([^/]+)/+([^/]+)/+([0-9]+)$
dispatch.cgi?module=$1&controller=$2&action=$3&id=$4 [QSA,L]
RewriteRule ^([^/]+)/+([^/]+)/+([^/]+)$
dispatch.cgi?module=$1&controller=$2&action=$3 [QSA,L]
RewriteRule ^([^/]+)/+([^/]+)/+$
dispatch.cgi?module=$1&controller=$2&action=index [QSA,L]
ErrorDocument 500 /500.html
ErrorDocument 404 /404.html
basically this reads: re-write only those urls which are neither files nor
directories. this saves us from having to even care if the request has a query
string, etc. since only virtual urls are re-written ''real''
ones never run the
risk of being munged.
now, the deault .htaccess file no doubt has subtleties i''m unaware of,
in
particular how it works with rails notion of link generation and also
i''ve no
idea how/if it works with webrick, but so far this simple approach not only
works - but it works when rails apps are not in the webroot. i imagine this
is an incomplete solution but feel there must be somthing simpler.
thoughts?
kind regards.
-a
--
==============================================================================|
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| When you do something, you should burn yourself completely, like a good
| bonfire, leaving no trace of yourself. --Shunryu Suzuki
===============================================================================