Lorenzo Gil Sanchez wrote:
> Hi,
> I know Zope3 has great support for virtual hosting and you can easily
> set it up using the Rewrite module of Apache as described here:
> http://www.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/Zope3Book/virtualhosting.html
> My problem is that my hosting provider does not allow me to create
> custom rewrite rules so I need to do the same in Zope3 side.
> Basically I want to change all request with the form
> http://www.mysite.com/$1 to http://localhost:8080/site_folder/++vh
> ++http:www.mysite.com:80/++$1
> I guess I need to slightly change Zope publishing mechanism and I saw
> IVirtualHostRoot in zope.publisher.interfaces.http. Probably calling
> setVirtualHostRoot when the traversal is at 'site_folder' is what I need
> but I have no clue about where should I do that.

Write a custom traversal adapter:

from zope.interface import implementsOnly
from zope.component adapts
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.app.container.interfaces import IContainer
from zope.app.container.traversal import ItemTraverser

class IVirtualHostRoot(IContainer):
    """We assume that the roots of virtual hosts are containers"""

class VirtualHostRootTraverse(ItemTraverser):
    adapts(IVirtualHostRoot, IBrowserRequest)

    def publishTraverse(self, request, name):
        return super(VirtualHostRootTraverse,
self).publishTraverse(request, name)

<adapter factory=".VirtualHostRootTraverse" permission="zope.Public" />

Untested, no warranties.


Zope3-users mailing list

Reply via email to