[Zope] redirect to a renamed folder

Tim Hicks tim@sitefusion.co.uk
Fri, 21 Jun 2002 19:45:39 +0100

Now I'm pretty sure this is some sort of faq, but I'm really having trouble
doing what I thought would be simple.

The Problem:

I have a site which needs to have one of its subfolders renamed from (say)
'foo' to 'bar'.  All subfolders within 'foo' (now 'bar') are the same.  No
problem so far, but people will have the old url's bookmarked, so I want to
redirect people requesting for example: /site/foo/blacksheep to

What I've Tried:

I figured I'd user standard_error_message to catch 'NotFound' errors, and
perform a redirect.  This is proving more difficult than I'd anticipated.
Here is what I came up with:

<dtml-if "error_type">
  <dtml-if "error_type == 'NotFound'">
    <dtml-let new_path="_.string.join(_.string.split(error_value, '/')[2:],
    <dtml-call "RESPONSE.redirect(''+new_path,
status=301, lock=1)">
missed it

The problem is, this seems to redirect to something looking like> (including the >).  I guess 'error_value'
is not the variable I want.  I thought maybe I would want
TraversalRequestNameStack, but that doesn't appear right either.  Really, I
want a list of url segments so I can drop in my new folder name in place of
the old one, rebuild the url then redirect, but I'm not sure how to do that.
Any ideas?



ps Another way I thought of was to maintain an empty folder named 'foo' with
an accessrule python script in it that catches the traverse_subpath and does
a redirect, but I'm not sure if that should even work in theory.  I haven't
used accessrules before, and I had trouble getting things to work.  From the
archives, I found that I can't use RESPONSE.redirect() from an accessrule,
but have to use raise.  However, I couldn't get this to work either.