Re: [Zope] redirect to a renamed folder
Just to let people know, I solved my problem of changing a folder name and catching old links to it. Indirect thanks must go to Casey Duncan who posted something to this list saying that python scripts halt traversal so they can populate their 'traverse_subpath' binding. I got things working by creating the script below with the old name of the folder ('cfhl' in this case). I knew it'd be easy in the end :-) tim ps context.path() is just a python script to get me a suitable url for the root of the site. ---- #Catches urls pointing to the old /cfhl/* folder tree #Redirects them to the new /hlsm/* tree import string context.REQUEST.RESPONSE.redirect(context.path()+'/hlsm/'+string.join(traverse_subpath, '/')) ----
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Tim Hicks Sent: Friday, June 21, 2002 11:46 AM To: zope@zope.org Subject: [Zope] redirect to a renamed folder
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 /site/bar/blacksheep.
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('http://192.168.2.2:9980/test/'+new_path, status=301, lock=1)"> </dtml-let> </dtml-if> <dtml-else> missed it </dtml-if>
The problem is, this seems to redirect to something looking like http://192.168.2.2:9980/test/H2> (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?
cheers
tim
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.
participants (1)
-
Tim Hicks