[Zope-dev] Using the SiteAccess Product for Virtual Hosting

Evan Simpson evan@4-am.com
Sat, 25 Sep 1999 01:56:10 -0500


Now that I've thrown the first version of SiteAccess out into the wide
world, and had a rest, I suppose a bit of documentation is in order.

Here's an example of how virtual hosting is supposed to work with this
Product.

I actually use a PythonMethod for this, for obvious reasons, but I
suspect many people will not want quite that much alpha code in their
life at once, so I'll present (untested) DTML Method examples.

In the Zope root, I place a DTML Method called RewriteRule with the
following body:

<dtml-with "_(site = {'www.tk.com': '/tk', 'shop.tk.com': '/tk/shop',
'www.other.org': '/other'}.get(HTTP_HOST, _.None) )">
  <dtml-if site>
    <dtml-call "REQUEST.set_path(site + PATH_INFO)">
    <dtml-call "REQUEST.set('SiteRootURL', 'http://'+HTTP_HOST)">
  </dtml-if>
</dtml-with>

If I wanted IP:PORT based rewriting, I'd use:

<dtml-with "_(site_pair={'10.0.0.10:80': ('/tk', 'www.tk.com'),
...}.get(HTTP_SOCKET_IP+':'+HTTP_SOCKET_PORT, None) )">
  <dtml-if site_pair>
    <dtml-call "REQUEST.set_path(site_pair[0] + PATH_INFO)">
    <dtml-call "REQUEST.set('SiteRootURL', 'http://'+site_pair[1])">
  </dtml-if>
</dtml-with>

In each of the Zope folders '/tk', '/tk/shop', and '/other', I add a
SiteRoot object.  I give them descriptive titles, but they don't really
need any configuring.

In the Zope root, I choose 'Set Access Rule' from the drop-down list,
and type 'RewriteRule' into the form and OK it.

At this point, any request with HTTP_HOST 'www.tk.com' will be rewritten
to go through folder '/tk' first, but won't include it in URLn's or
absolute_url() calls.

I lie.  This is what *will* happen when the product is done.  At the
moment, what you'll get is an AttributeError complaining that the
REQUEST object doesn't have an attribute 'set_path', because I haven't
written it yet.  Also, SiteRoots don't do anything but print a
diagnostic message when traversed.

I could use some design help.  Would REQUEST.set_path be the Right
Thing, here?  Probably, and it's not my main concern.  I'm much more
worried about how exactly SiteRoots should accomplish their tasks.

After digging through the Zope source, it seems that *at least*
REQUEST.steps and REQUEST['URL'] need to be changed, and absolute_url
re-implemented, but there's a whole tangle of twisty little CGI and Zope
variables, all almost alike, holding bits and pieces of the URL.
Frankly, I think it would be valuable if all that were cleaned up, but I
don't feel like I know enough to do it right.