[mod_python] handler for any request

Volodya volodya at real.samuraj.org
Fri May 7 17:22:59 EST 2004

On Fri, May 07, 2004 at 11:27:21AM +0400, Alexey Nezhdanov wrote:
> Hello.
> I have an slightly unusual question:How I can set up apache to route _all_ 
> incoming requests to the same python handler irrelevantly of request itself.
> I want to design a back-proxy server gathering all requests going to 
> particular web-server, requesting the interested information itself from the 
> "real" server and feeding the server answer back to client.
> I.e. I wish for the
> and all other requests that are directed to going to python 
> handler.
> Is such scheme is possible with mod_python?

Try this:

.htaccess file:

AddHandler mod_python .py
SetHandler mod_python
PythonHandler proxy
PythonDebug On

proxy.py file:

from mod_python import apache

def handler(req):
    req.content_type = "text/plain"
    return apache.OK

i've placed boths file in /proxy directory under the documents root,
so when i address url 'http://SERVER/proxy/test/one/two?three=four&five=six'
the output is:

GET /proxy/test/one/two?three=four&five=six HTTP/1.1

So proxying GET-requests is pretty simple. With POST-methods You'll have
more work to do.

More information about the Mod_python mailing list