[mod_python] TransHandler help?

Alan Kennedy modpython at xhaus.com
Mon Jan 7 19:32:10 EST 2002

Greetings All,

And many thanks to Grisha for an excellent body of work.

I'm trying to get a PythonTransHandler working.

What I am trying to do is modify an URL before it goes through standard
Apache processing. (See below for an explanation why, if you wish)

Could someone possibly give me a simple example (including
configuration) of how I could, for example, change every request for a
.html file to a request for a .xyz file. That is, a request for


would become a request for


*without* sending a redirect back to the client. Or a more sophisticated
example, how could I turn a request for


into a request for


Many thanks for any help offered.



P.S. I'm working with modpython 2.7.6, win2k, apache 1.3.22 and Python

Why: I am trying to implement URL rewriting for session tracking. Rather
than try to modify every <a href> and <form action> to contain a session
ID, I was hoping to take a quick solution using a <base href> element in
<head>. In fact I was hoping to encode several parameters like this,
i.e. as pseudo-directory names. Why do it this way, rather than setting
all the parameters as query args, i.e. "?sessID=abc123&command=update".

For a couple of reasons:-

1. Because it looks far neater in the URL
2. Because I can put all that stuff into the <base href>, which is
simpler in code terms, because I don't have to worry about <a href> and
<form action> adding their own query parameters, and potentially having
two "?" query delimiters in the URI, which is invalid.

So, the way it would work is this:

A HTML document (H) is transmitted which contains the parameters as
"directory names" in the <base href>

When the client activates a link in H or submits a form from H, I
extract the parameters out of the requested URI, and execute whatever

The problem is that Apache complains if any of the "pseudo directories"
does not physically exist. Which is a rather a pain. That's why I need
to change the URL before Apache gets at it, which the documentation
implies TransHandler can do. I quote :- "This routine gives allows for
an opportunity to translate the URI into an actual filename, before the
server's default rules (Alias directives and the like) are followed. "

More information about the Mod_python mailing list