Manfred Stienstra
manfred.stienstra at dwerg.net
Mon Dec 20 12:29:05 EST 2004
On Mon, 2004-12-20 at 11:42 -0500, Alexis Marrero-Narváez wrote: > All, > > How can I setup Apache2, in such way that I only need one index.py for > all subdirectories. For instance here is a directory structure: > /persons > /john > /daughters > /anna > /alicia > /mary > index.py > > I want the index.py in /persons to be used everytime the user access > any URI under /persons. So if the user GET > http://host.com/persons/john/daugthers/ apache handles the request by > sending it to index.py inside /persons instead of trying to get > /persons/john/daughters/index.py? > > Are there any tricks other than using mod_rewrite? Remember, introspection is your friend. Something like this: handler.py: import stuff def handler(req): parts = req.request_uri.split('/') try: getattr(stuff, "handle_%s" % parts[1])(req, parts[1:]) except AttributeError: stuff.handle_error(req, parts) stuff.py: def handle_john(req, parts): pass def handle_mary(req, parts): pass def handle_error(req, parts): req.content_type='text/plain' req.status = 404 req.write("you done screwed up!")
|