[Zope] catching shorter URLs

Aaron Maupin maupin at pastrytech.com
Mon Jul 9 10:25:31 EDT 2007


Dieter Maurer wrote:

 > A "SiteAccess" "AccessRule" can do such things for you.
 >
 > Look around whether you find some documentation about "AccessRule"s
 > and how to tweak the request object in such a rule.

Thanks Dieter!  That indeed did the trick.  It took a lot of digging 
around online (and several times undoing the last edit because it made 
the folder I was working in uneditable with the management interface) 
but in the end I was successful.

For posterity:

A Virtual Host Monster mapping sends any request with the "games" 
subdomain to a special folder with the following access rule:

#####

request = context.REQUEST

#determine title (last part of URL)

url = request.other['ACTUAL_URL']
if len(url) > 0:
     if url[-1] == '/':
         url = url[:-1]
splitpath = url.split('/')
target = splitpath.pop()

#add title as form data to request object

request.form['gametitle'] = target

#rewrite path - display_game is a Python script in the root of
#Zope, so by adding its name to the namestack it will be found.
#Not added if I'm editing the script (hack) so I'm not locked out.

namestack = request.other['TraversalRequestNameStack']

if namestack[0][:6] != 'ZPytho' and namestack[0][:6] != 'manage':
     request.other['TraversalRequestNameStack'] = ['display_game']

#####

So far it works well.  I can visit

     games.mydomain.com/Tetris

and

     www.mydomain.com/display_game?gametitle=Tetris

interchangably.

Aaron


More information about the Zope mailing list