Graham Dumpleton
grahamd at dscpl.com.au
Mon Dec 18 18:47:17 EST 2006
Mark Harrison wrote .. > 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. > Based on fact that your directory has xmlrpc in the path and that you are actually seeing the the 301 HTTP response, I am going to guess that you aren't using a web browser but an XML-RPC client. If this is the case then you are most likely seeing the 301 response because you are using a URL which doesn't have the trailing slash on it. Ie., /x1/ If you use the trailing slash, does it then work? The reason the slash is required is that Apache does what is called trailing slash redirection by default. That is, whenever you use a URL which maps to a physical directory, it will send back a redirect response telling the client to send the request again but this time with the trailing slash appended. It does this to ensure that the base URL for any index file is correct and that relative page references in a HTML based index page resolve correctly. Since you are setting the PythonPath directive to where your module file is potentially installed anyway, you are possibly just better of using: # Move your stuff out of the document tree and you will not need this. <Directory "/Users/mh/mp/htdocs/xmlrpc/x1"> deny from all </Directory> # Use Location instead of Directory. <Location /x1> # The PythonPath may have to be adjusted. PythonPath "sys.path+['/Users/mh/mp/htdocs/xmlrpc','/Users/mh/mp/htdocs/xmlrpc/x1']" SetHandler mod_python PythonHandler x1 </Directory> By using Location directive, and with location itself not having trailing slash, Apache will not do trailing slash redirection and just pass any request starting with /x1 through to your handler. Graham > 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 > </Location> > > <Directory "/Users/mh/mp/htdocs/xmlrpc/x1"> > #SetHandler mod_python <--also tried this > AddHandler mod_python .py > PythonHandler x1 > DirectoryIndex index.py > </Directory> > > > > > 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!
|