[mod_python] eliminating last foo.py from url?

Mark Harrison mh at pixar.com
Mon Dec 18 14:37:45 EST 2006

Graham Dumpleton wrote:
> Mark Harrison wrote ..
>> Mark Harrison wrote:
>>> So, I've pretty much copied the standard directory configuration,
>>> <Directory "/apache/htdocs/appserv">
>>>         AddHandler mod_python .py
>>>         PythonHandler appserv
>>>         PythonDebug On
>>> </Directory>
>>> and I can reference my service by http://foo.com/appserv/appserv.py
>>> (or any other .py in that directory, of course).
>>> How can I make it such that I can reference with the trailing foo.py?
>> Alias seems to be the key...
>> <Directory "/Users/mh/mp/htdocs/xmlrpc/x1">
>>    AddHandler mod_python .py
>>    PythonHandler x1
>> </Directory>
>> Alias /x1 /Users/mh/mp/htdocs/xmlrpc/x1/.py
> As indicated in previous response on list, the DirectoryIndex directive is more
> appropriate for having directory access mapped to a mod_python handler when
> you are using AddHandler rather than SetHandler. I would recommend against
> trying to fiddle things with an Alias directive as it will not work for subdirectories
> and that your left hand side doesn't use a trailing slash may cause other issues
> as well with base url determination and relative URLs in HTML files which can
> cause problems with your web application.
> Why can't you use the following?
>   <Directory "/Users/mh/mp/htdocs/xmlrpc/x1">
>      AddHandler mod_python .py
>      PythonHandler x1
>      # Value to DirectoryIndex should be anything with .py
>      # extension, it does not actually have to exist.
>      DirectoryIndex index.py
>   </Directory>

It's probably me being clueless, but no matter what I fiddle with I always
get a "301 Moved Permanently" result.

I've got a pretty pared-down httpd.conf, so I don't think I'm
getting any unexpected interactions from other modules.


ServerRoot "/Users/mh/mp"

Listen 9000
StartServers 2

ErrorLog logs/error_log
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog logs/access_log common

LoadModule python_module modules/mod_python.so
PythonPath "sys.path+['/Users/mh/mp/htdocs/xmlrpc','/Users/mh/mp/htdocs/xmlrpc/x1']"

DocumentRoot "/Users/mh/mp/htdocs"

<Location /mpinfo>
   SetHandler mod_python
   PythonHandler mod_python.testhandler

<Directory "/Users/mh/mp/htdocs/xmlrpc/x1">
   #SetHandler mod_python <--also tried this
   AddHandler mod_python .py
   PythonHandler x1
   DirectoryIndex index.py

>   Alias /x1 /Users/mh/mp/htdocs/xmlrpc/x1
> Did you read the article referenced in prior replies? Namely:
>   http://www.dscpl.com.au/wiki/ModPython/Articles/SetHandlerVersusAddHandler
> and which talks about using DirectoryIndex when using AddHandler.

I did read this, and it seems to make sense... I just couldn't get
it to work :-(

Any clues appreciated!

Mark Harrison
Pixar Animation Studios

More information about the Mod_python mailing list