Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

mod_ruby used to mimic rewrite

3 views
Skip to first unread message

jm

unread,
Aug 9, 2004, 7:53:50 AM8/9/04
to
The scenario is the need to rewrite a request for dummy.example.com to
another directory. The reasoning behind this is a quirk in our current
set up so we can map algorithmically map and it would involve too many
rewrite rules to handle manually. The problem is that this seems to be
working to the point of modifying the filename, but apache returns 403
to the browser and logs

(2)No such file or directory: Can't open directory for index:
/var/www/example.com/dummy/

or some other error even though index.rhtml and index.html exist. As
far as I can tell it could be either a problem with the Apache::SiteMap
class below or the apache config. Also on that matter does anyone know
how I can get the module triggered on the host instead of the
directory?

I've attempted to look at http://modrubby.net/ but it seems to be down
so I've been using the google cache. Anyone care to give me a few
pointers, here's extracts from the relevant files,

apache config:

<IfModule mod_ruby.c>
RubyRequire sitemap
<Directory /var/www/example.com/>
SetHandler ruby-object
RubyHandler Apache::SiteMap.instance
Options +Indexes
DirectoryIndex index.rhtml index.html index.htm index.html.var
</Directory>

# other stuff
</IfModule>

sitemap.rb contains, with debugging code removed,

require "singleton"
module Apache
class SiteMap
include Singleton
@@host2dir = {'dummy.example.com' => 'dummy/'}

def handler(r)
r.content_type = 'text/html'
r.send_http_header
exit(Apache::OK) if r.header_only?

document_root = r.server.document_root
(document_root[-1] != "/") && document_root += "/"

if @@host2dir.has_key?(r.headers_in['Host'])
newdocroot = document_root + @@host2dir[r.headers_in['Host']]
filename = r.filename.sub("#{document_root}", newdocroot)
puts "sub: #{document_root} #{newdocroot} #{filename}<br>"
end
r.filename = filename
return Apache::DECLINED
end
end
end

Kirk Haines

unread,
Aug 9, 2004, 9:36:27 AM8/9/04
to
On Mon, 9 Aug 2004 20:53:50 +0900, jm wrote

> The scenario is the need to rewrite a request for dummy.example.com
> to another directory. The reasoning behind this is a quirk in our
> current set up so we can map algorithmically map and it would
> involve too many rewrite rules to handle manually. The problem is
> that this seems to be working to the point of modifying the filename,
> but apache returns 403 to the browser and logs

I just woke up and my head hurts and I'm operating off the top of my head,
here, to take this for what it's worth (LOL) but I believe what you want to
do here is to use mod_ruby to write a translation handler so that your code
can give Apache a different address to use during the address translation
phase. The mod_ruby directive is

RubyTransHandler CLASSNAME


Hope that helps,

Kirk Haines

jm

unread,
Aug 9, 2004, 11:03:54 PM8/9/04
to
This has got me as far as having one possible solution. It's not
exactly what I was after as I would have been able to indicate any
arbitrary directory instead of just tweaking the uri. This limits it
to being under document root unless anyone can think of a simple way
for this arbitrary method would working this uri rewrite will do. Time
to run out the door again. Thanks.

J.

Kirk Haines

unread,
Aug 10, 2004, 1:10:41 AM8/10/04
to
On Tue, 10 Aug 2004 12:03:54 +0900, jm wrote

> This has got me as far as having one possible solution. It's not
> exactly what I was after as I would have been able to indicate any
> arbitrary directory instead of just tweaking the uri. This limits
> it to being under document root unless anyone can think of a simple
> way for this arbitrary method would working this uri rewrite will
> do. Time to run out the door again. Thanks.

Move to an earlier phase for your handler. If your handler is a
RubyInitHandler, I believe you should be able to alter the request pretty
freely as your Ruby code will gain access to it very early in the process of
handling it.


Good luck,

Kirk Haines

0 new messages