[mod_python] how do I eliminate the .py extension in url?

Graham Dumpleton grahamd at dscpl.com.au
Sat Feb 12 21:12:06 EST 2005

On 12/02/2005, at 3:44 PM, Graham Dumpleton wrote:

> On 12/02/2005, at 3:18 PM, Damjan wrote:
>>> Put the following in httpd.conf:
>>> SetHandler mod_python
>>> PythonHandler module.path.to.handler.file
>>> Then in the handler file, def a handler that looks for python scripts
>>> and loads them based on the req.uri. The attached very crufty handler
>>> might be a good source of amusement.
>>> def handler(req):
>>>     # 1. If the file exists & not a directory, serve it.
>>>     filepath = req.document_root() + req.uri
>>>     if (os.access(filepath, os.R_OK)
>>>     and not os.path.isdir(filepath)) :
>>>         # req.write("sending file\n")
>>>         req.sendfile(filepath)
>>>         return apache.OK
>> Why don't you return apache.DECLINE, that way even php scripts would
>> work correctly.
> Hmmm, when I have tried mixing PHP in the same directory and used
> apache.DECLINED to throw back unhandled requests to Apache, the PHP
> file wouldn't get processed by the PHP module and instead the raw
> file would be returned. Thus it has been necessary to have:
>   <Files *.php>
>   SetHandler None
>   </Files>
> This was though on Apache 1.3 and I haven't tried it on Apache 2.0.

I have now tried this on Apache 2.0, and even there, returning 
doesn't result in PHP files being processed correctly without turning 
mod_python handling of PHP, so that the PHP module has first go at it.

If you have actually got this working, I would like to know how as it 
be useful in avoiding the step of disabling the handler for PHP files.


More information about the Mod_python mailing list