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

Graham Dumpleton grahamd at dscpl.com.au
Fri Feb 11 23:44:18 EST 2005


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.

Graham



More information about the Mod_python mailing list