[Zope3-Users] Re: Virtual hosting problem
Philipp von Weitershausen
philipp at weitershausen.de
Wed Aug 30 04:38:44 EDT 2006
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)
implementsOnly(IBrowserPublisher)
def publishTraverse(self, request, name):
request.setVirtualHostRoot([])
return super(VirtualHostRootTraverse,
self).publishTraverse(request, name)
<adapter factory=".VirtualHostRootTraverse" permission="zope.Public" />
Untested, no warranties.
Philipp
More information about the Zope3-users
mailing list