[Zope] redirection of whole sub-trees
Jay, Dylan
djay@lucent.com
Fri, 10 Sep 1999 15:09:34 +1000
> -----Original Message-----
> From: Jay, Dylan
> Sent: Thursday, September 09, 1999 09:17
> To: 'Martijn Pieters'; Jay, Dylan; 'alex@mop.no'
> Cc: 'zope@zope.org'
> Subject: RE: [Zope] redirection of whole sub-trees
>
>
> > -----Original Message-----
> > From: Martijn Pieters [mailto:mj@antraciet.nl]
> > Sent: Wednesday, September 08, 1999 19:41
> > To: Jay, Dylan; 'alex@mop.no'
> > Cc: 'zope@zope.org'
> > Subject: Re: [Zope] redirection of whole sub-trees
> >
> >
> > At 08:49 08/09/99 , Jay, Dylan wrote:
> > >Is it possible to make this product redirect whole
> > sub-trees? I'm migrating
> > >a Zop1 site using cgi under IIS to Zope2 using ZServer. I
> > want to redirect
> > >all the "/cgi-bin/zope.exe/(.*)" queries to "/\1" using the
> > grouping syntax.
> > >since I'm not using apache I can't use mod_rewrite so this
> > is the only
> > >option I can think of at the moment and I can't upgrade
> > until I have the
> > >redirection in place.
> > >
> > >I can do the substitution no prob by changing after line 95 like so
> > >
> > > for k in self.Mappings.keys():
> > > m = re.match(k, Name)
> > > if m:
> > > Name = re.sub(k, self.Mappings[k], Name)
> > >
> > >But "Name" is not the remainder of the url :(
> >
> > I believe there is a redirection product doing just that:
> >
> > http://www.zope.org:18200/Members/astaubo/Redirector
>
> Opps, didn't make myself clear. The Redirector product is
> what I'm using and it doesn't do that. It redirects only
> objects in one folder not and entire subtree.
Ok, here is the patch that will allow the redirection of subtrees. Whats
more it does reg-exp substitutions. The __bobo_traverse__ method in
Redirector.py should look like this.
def __bobo_traverse__(self, REQUEST, Name = ''):
if Name[:6] != 'manage':
import ExtensionClass
class doTraverse(ExtensionClass.Base):
def __init__(self, path, Mappings, Target, HardMap):
self.path = path
self.Mappings = Mappings
self.Target = Target
self.HardMap = HardMap
def __bobo_traverse__(self, REQUEST, Name = ''):
self.path = self.path + '/' + Name
return self.__class__(self.path, self.Mappings, self.Target,
self.HardMap)
def __call__(self, REQUEST):
path = self.path
if REQUEST['QUERY_STRING']:
path = path + "?" + REQUEST['QUERY_STRING']
for k in self.Mappings.keys():
if re.match(k, path):
path = re.sub(k, self.Mappings[k], path)
break
else:
if self.HardMap:
raise 'Redirect', self.Target
def Merge(Target, Url):
if Url[:5] == 'http:' or Url[:4] == 'ftp:':
return Url
else:
return Target + Url
raise 'Redirect', Merge(self.Target , path)
return doTraverse(Name, self.Mappings, self.Target, self.HardMap)
if hasattr(self, 'aq_base'):
b = self.aq_base
if hasattr(b, Name):
return getattr(self, Name)
try:
return self[Name]
except:
return getattr(self, Name)