[Zope] Smart redirecting? Help me in a script call in standard_error_message

e-Musty emusty@mailbox.hu
Tue, 29 Jan 2002 02:37:13 +0100


This is a multi-part message in MIME format.

------=_NextPart_000_001C_01C1A86D.DB79D1A0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

I'm developing a new site under Zope to replace our old one. This
development came with a complete restructuring of things, including folder
structure and file names. I thought it would be great to have a smart
redirector that would redirect requests for the old (currently non-existing)
URLs to the corresponding new URLs.

I however did want to avoid writing hundreds of pages (DTMLs) just for
containing the well-known REQUEST.RESPONSE.redirect('/newfoo') expr.
Instead, I've made a small Python script to do the job by defining a list of
tuples for the possible bad requests in which each element contain two
items, the old URL (URI) and the corresponding new. To say so, I've made a
mapping from old directories to new directories in the following manner:

Assume that you had a folder named "/foo/bob" and the HTML files
"/foo/foo.html", "/foo/foo2.html" and "/foo/bob/bob.html". The new site,
however, contains the folder "/newfoo" as the corresponding for "foo" and
"/newbob" for the old "/foo/bob/". The corresponding docu for
"/foo/foo.html" is "/newfoo/newfoo_html", while "/foo/foo2.html" does not
have such a corresponding page and the index_html of "/newfoo" should be
displayed.
In this case you should make a mapping like:

mappings = [
    ('/foo/bob', '/newbob'),
    ('/foo/foo.html', '/newfoo/newfoo_html'),
    ('/foo', '/newfoo')
]

Iterating over the list and matching the actual REQUEST's URL to the first
item of each tuple, the right URLs are constructed. Then the client has to
be redirected to the new URL. Let's call the script doing the whole job
"redirector"

Then I changed my standard_error_message so that it first invokes the
redirector script in case of NotFound errors with the <dtml-call> tag.

What my problem is: the redirector script cannot be called, although it is
in the same folder as standard_error_message, because Zope encounters a 404
error and displays its own standard error message.

Does any good fellow have any idea on how to call that script without having
Zope so crazy?


Thanks in advance,
e-Musty

------=_NextPart_000_001C_01C1A86D.DB79D1A0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2712.300" name=3DGENERATOR></HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D474581801-29012002>I'm =
developing a new=20
site under Zope to replace our old one. This development came with a =
complete=20
restructuring of things, including folder structure and file names. I =
thought it=20
would be great to have a smart redirector that would redirect requests =
for the=20
old (currently non-existing) URLs to the corresponding new=20
URLs.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D474581801-29012002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D474581801-29012002>I =
however did want=20
to avoid writing hundreds of pages (DTMLs) just for containing the =
well-known=20
REQUEST.RESPONSE.redirect('/newfoo') expr.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D474581801-29012002>Instead, I've made a=20
small Python script to do the job by defining a list of tuples for the =
possible=20
bad requests in which each element contain two items, the old URL (URI) =
and the=20
corresponding new. To say so, I've made a mapping from old directories =
to new=20
directories in the following manner:</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D474581801-29012002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D474581801-29012002>Assume =
that you had=20
a folder named "/foo/bob" and&nbsp;the HTML files&nbsp;"/foo/foo.html",=20
"/foo/foo2.html"&nbsp;and "/foo/bob/bob.html". The new site, however, =
contains=20
the folder "/newfoo" as the corresponding for "foo" and "/newbob" for =
the old=20
"/foo/bob/". The corresponding docu for "/foo/foo.html" is=20
"/newfoo/newfoo_html", while "/foo/foo2.html" does not have such a =
corresponding=20
page and the index_html of "/newfoo" should be =
displayed.</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN class=3D474581801-29012002>In =
this case you=20
should make a mapping like:</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D474581801-29012002></SPAN></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D474581801-29012002>mappings =3D [=20
</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D474581801-29012002>&nbsp;&nbsp;&nbsp;=20
('/foo/bob', '/newbob'), </SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D474581801-29012002>&nbsp;&nbsp;&nbsp;=20
('/foo/foo.html', '/newfoo/newfoo_html'),</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN =
class=3D474581801-29012002>&nbsp;&nbsp;&nbsp;=20
('/foo', '/newfoo') </SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2><SPAN=20
class=3D474581801-29012002>]</SPAN></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><SPAN class=3D474581801-29012002><FONT face=3DArial =
size=3D2>Iterating over the=20
list and matching the actual REQUEST's URL to the first item of each =
tuple, the=20
right URLs are constructed. Then the client has to be redirected to the =
new URL.=20
</FONT></SPAN><SPAN class=3D474581801-29012002><FONT face=3DArial =
size=3D2>Let's call=20
the script doing the whole job "redirector"</FONT></SPAN></DIV>
<DIV><SPAN class=3D474581801-29012002><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D474581801-29012002><FONT face=3DArial size=3D2>Then I =
changed my=20
standard_error_message so that it first&nbsp;invokes the redirector =
script in=20
case of NotFound errors with the &lt;dtml-call&gt; =
tag.</FONT></SPAN></DIV>
<DIV><SPAN class=3D474581801-29012002><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D474581801-29012002><FONT face=3DArial size=3D2>What =
my problem is:=20
the redirector script cannot be called, although it is in the same =
folder as=20
standard_error_message, because Zope encounters a 404 error and displays =
its own=20
standard error message.</FONT></SPAN></DIV>
<DIV><SPAN class=3D474581801-29012002><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D474581801-29012002><FONT face=3DArial size=3D2>Does =
any good fellow=20
have any idea on how to call that script without&nbsp;having Zope so=20
crazy?</FONT></SPAN></DIV>
<DIV><SPAN class=3D474581801-29012002><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D474581801-29012002><FONT face=3DArial=20
size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D474581801-29012002><FONT face=3DArial size=3D2>Thanks =
in=20
advance,</FONT></SPAN></DIV>
<DIV><SPAN class=3D474581801-29012002><FONT face=3DArial=20
size=3D2>e-Musty</FONT></SPAN></DIV></BODY></HTML>

------=_NextPart_000_001C_01C1A86D.DB79D1A0--