mod_ruby used to mimic rewrite

J

jm

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
 
K

Kirk Haines

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
 
J

jm

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

Kirk Haines

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top